2017-01-22 3 views
0

Hallo liebe Android ProgrammiererAndroid-Layout nicht alle Kinder zeigen

Im auf einem App sitzen, in dem ich möchte Kontakte anzuzeigen (realisiert als framelayouts) in einem 2 × n Gitter.

Dafür verwende ich eine ScrollView, in der ich ein einzelnes FrameLayout platzierte, um alle anderen FrameLayouts zu halten.

Ich verwende FrameLayouts, weil ich die gleichen Probleme mit einem LinearLayout hatte.

Zu Testzwecken habe ich es in FrameLayout geändert und setze jetzt die X- und Y-Koordinaten selbst, anstatt den linearen Layouts zu vertrauen, um die Arbeit für mich zu erledigen.

Das Problem ich habe, ist, dass es zeigt nur 2 der FrameLayouts aka Kontakte in meiner app wie im Bild zu sehen allthough alles gesetzt richtige inr eGard zu x, y coodrdinates up, Breite, Höhe usw. ... enter image description here

Die Methode, die Sie hier sehen, dient zum Erstellen der Kontakte als Viewgroups bestehend aus einem Imageview und einem TextView.

contactsparent ist das framelayout zum Halten der Kontakte.

public void addContactItem(Person... p) 
{ 
    Display display = main.getWindowManager().getDefaultDisplay(); 
    Point size = new Point(); 
    display.getSize(size); 

    int width=size.x; 
    for(Person pers:p) 
    { 
     String name=pers.name; 
     Bitmap photo=pers.photo; 
////////////////////////////////////////////////////////// 
     FrameLayout lltmp=new FrameLayout(main); 
     lltmp.setLayoutParams(new ViewGroup.LayoutParams((int) (0.375 * width), (int) (0.4 * width))); 
     lltmp.setBackgroundColor(Color.YELLOW); 

////////////////////////////////////////////////////////// 
     ImageView imgtmp=new ImageView(main); 
     imgtmp.setLayoutParams(new ViewGroup.LayoutParams((int) (0.375 * width), (int) (0.3 * width))); 
     imgtmp.setImageBitmap(photo); 

////////////////////////////////////////////////////////// 
     TextView tvtmp=new TextView(main); 
     tvtmp.setLayoutParams(new ViewGroup.LayoutParams((int) (0.375 * width), (int) (0.1 * width))); 
     tvtmp.setText(pers.name); 
     tvtmp.setBackgroundColor(Color.RED); 
     tvtmp.setY((int) (0.3 * width)); 


     lltmp.setX(contactsparent.getChildCount() % 2 == 0 ? 0 : ((int) (0.375 * width))); 
     lltmp.setY(contactsparent.getChildCount()/2 * (int) (0.4 * width)); 

     lltmp.addView(imgtmp); 
     lltmp.addView(tvtmp); 

     contactsparent.addView(lltmp); 

     Log.w("fdsfsf", contactsparent.getChildCount() + " x= " + (contactsparent.getChildCount() % 2 == 0 ? 0 : ((int) (0.375 * width))) + " | y=" + contactsparent.getChildCount()/2 * (int) (0.4 * width)); 
    } 
} 

Was ist hier schief gelaufen ?! Warum zeigt meine App nur 2 der Kontakte, obwohl ich weiß, dass es 10 geben muss, da der Parameter (Person ... p) ein Array von 10 Personen sein wird, mit denen ich die obige Methode anrufe.

Die Log.v am Ende des Verfahrens gibt diese Ausgabe:

01-22 19:29:34.408 820-820/com.jaielsoft.www.emergencyapp W/fdsfsf: 1 x= 405 | y=0 
01-22 19:29:34.409 820-820/com.jaielsoft.www.emergencyapp W/fdsfsf: 2 x= 0 | y=432 
01-22 19:29:34.410 820-820/com.jaielsoft.www.emergencyapp W/fdsfsf: 3 x= 405 | y=432 
01-22 19:29:34.461 820-820/com.jaielsoft.www.emergencyapp W/fdsfsf: 4 x= 0 | y=864 
01-22 19:29:34.462 820-820/com.jaielsoft.www.emergencyapp W/fdsfsf: 5 x= 405 | y=864 
01-22 19:29:34.463 820-820/com.jaielsoft.www.emergencyapp W/fdsfsf: 6 x= 0 | y=1296 
01-22 19:29:34.464 820-820/com.jaielsoft.www.emergencyapp W/fdsfsf: 7 x= 405 | y=1296 
01-22 19:29:34.466 820-820/com.jaielsoft.www.emergencyapp W/fdsfsf: 8 x= 0 | y=1728 
01-22 19:29:34.467 820-820/com.jaielsoft.www.emergencyapp W/fdsfsf: 9 x= 405 | y=1728 
01-22 19:29:34.468 820-820/com.jaielsoft.www.emergencyapp W/fdsfsf: 10 x= 0 | y=2160 

UPDATE:

So anscheinend gibt es dieses Problem, warum ich die Childviews nicht sehen kann:

enter image description here

Dann sollte es ein Problem sein, wie ich die ViewGroups installieren, die meine Kontakte enthalten:

contactlayoutparent=new ScrollView(main); 

    contactlayoutparent.setLayoutParams(new ViewGroup.LayoutParams((int) (0.75 * width), (int) (0.725 * height))); 
    contactlayoutparent.setX(0.125f * width); 
    contactlayoutparent.setY(0.18f * height); 
    contactlayoutparent.setBackgroundColor(Color.BLUE); 

    contactsparent=new FrameLayout(main); 
    contactsparent.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
      ViewGroup.LayoutParams.MATCH_PARENT)); 

    contactlayoutparent.addView(contactsparent); 

edit2:

als über die xml gefragt: Es gibt keine xml ist aber in xml wäre es wie:

FrameLayout{ 
    ... 
    //Here comes the Contacts layout 
    ScrollView{ 
     FrameLayout{ 
      //Child1 
      FrameLayout{ 
      } 
      //Child2 
      FrameLayout{ 
      } 
      //Child3 
      FrameLayout{ 
      } 
      ... 
     } 
    } 
} 
+0

zeigen vollständige Code mit xml – androidXP

+0

, wie Sie es sehen können, beteiligt keine xml-Code ist, wie ich sie alle in Code tun –

+0

sehen das Update, wo man sehen kann, wie die Eltern wird ein Scroll einrichten In XML wäre es wie –

Antwort

0

Problem gelöst: nicht Listview Verwenden Sie, wenn Sie anzeigen möchten ein Gitter. Verwenden Sie Gridview statt: D

Verwandte Themen