Wie programm hinzufügen 2 Textview in einem linearen Layout
Hallo allerseits,
Ich erhalte die folgenden Felder "Name" und "Skoda" von API. Es wird x Anzahl der Gegenstände geben. Wie pro Design sollte ich sie wie im folgenden Bild zeigen.
Also habe ich beschlossen, zwei Textansicht programmatisch in einem linearen Layout namens "childLayout" wie folgt zu erstellen.
-- RelativeLayout
-- Linear Layout
-- TextView Textview --
-- Linear Layout
-- Linear Layout
-- TextView Textview --
-- Linear Layout
-- Linear Layout
-- TextView Textview --
-- Linear Layout
--RelativeLayout
Aber ich bekomme nicht die gewünschte Ausgabe. Bitte helfen Sie mir, dieses Problem zu beheben.
Hier Code:
TextView mType;
TextView mValue;
for (int i = 0; i < getDetailedDescAL.size(); i++) {
LinearLayout childLayout = new LinearLayout(
DetailedCategories.this);
LinearLayout.LayoutParams linearParams = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
childLayout.setLayoutParams(linearParams);
mType = new TextView(DetailedCategories.this);
mValue = new TextView(DetailedCategories.this);
mType.setLayoutParams(new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, 1f));
mValue.setLayoutParams(new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, 1f));
mType.setTextSize(17);
mType.setPadding(5, 3, 0, 3);
mType.setTypeface(Typeface.DEFAULT_BOLD);
mType.setGravity(Gravity.LEFT | Gravity.CENTER);
mValue.setTextSize(16);
mValue.setPadding(5, 3, 0, 3);
mValue.setTypeface(null, Typeface.ITALIC);
mValue.setGravity(Gravity.LEFT | Gravity.CENTER);
mType.setText(getDetailedDescAL.get(i).getmPropertyType());
mValue.setText(getDetailedDescAL.get(i).getmPropertyValue());
childLayout.addView(mValue, 0);
childLayout.addView(mType, 0);
RelativeLayout.LayoutParams relativeParams =
new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
relativeParams.addRule(RelativeLayout.BELOW);
Details.addView(childLayout, relativeParams);
// Details is the relative layout declared in XML
}
Die Ausgabe lautet:
Es scheint, wie die Textviews überschrieben werden. Wie man das löst.
Versuchen Sie, Ihre Ansichten in einer Linearlayout mit vertikaler Ausrichtung hinzuzufügen, anstatt in einem RelativeLayout. –