Programmgesteuert mithilfe MATCH_PARENT für ein RelativeLayout innen ein FrameLayout

Ich bin Unterklassen HorizontalScrollView (das ist ein FrameLayout) und das hinzufügen von ein RelativeLayout, um es programmatisch.

Dem FrameLayout korrekt füllt die übergeordnete Sicht, aber RelativeLayout innen nicht zeigen, bis.

MainActivity::OnCreate()

setContentView(R.layout.activity_main); 
CustomHorizontalScrollView custom = new CustomHorizontalScrollView(this); 
ViewGroup contentView = (ViewGroup) findViewById(R.id.content); 
contentView.addView(custom,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 180));

CustomHorizontalScrollView::Constructor()

this.setBackgroundColor(Color.MAGENTA);
relativeLayout = new RelativeLayout(context);
relativeLayout.setBackgroundColor(Color.BLACK);
this.addView(relativeLayout, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));

Ergebnis:

Programmgesteuert mithilfe MATCH_PARENT für ein RelativeLayout innen ein FrameLayout

Dem RelativeLayout sollte schwarz sein und füllen sollten Eltern aber nicht.

Komisch ist, dass wenn ich geben Sie die Breite und Höhe in Pixeln statt mit MATCH_PARENT, die RelativeLayout wird angezeigt.

this.addView(relativeLayout, new FrameLayout.LayoutParams(90, 90));

Programmgesteuert mithilfe MATCH_PARENT für ein RelativeLayout innen ein FrameLayout

Bedeutet das, dass ich nicht verwenden können, MATCH_PARENT, wenn programmgesteuert hinzufügen ein RelativeLayout zu einem FrameLayout? Oder bin ich etwas fehlt? Oder vielleicht HorizontalScrollView unterstützt nur ein Kind zu haben, mit fester Breite und Höhe?

Ich habe herausgefunden, dass der Aufruf relativeLayout.layout(l, t, r, b); in onLayout(boolean changed, int l, int t, int r, int b) macht das layout passen Elternteil. Jedoch, Untersichten nicht richtig schließen (ALIGN_PARENT_LEFT, ALIGN_PARENT_RIGHT).

InformationsquelleAutor Lumbi | 2014-02-16

Schreibe einen Kommentar