Come aggiungere a livello di codice 2 TextView in un layout lineare
Ciao a tutti,
sto ottenendo i seguenti campi "Nome" e "Skoda" da API. Ci sarà il numero x di oggetti come questo. Come da progetto, dovrei mostrarli come nell'immagine seguente.
Quindi, ho deciso di creare due textview a livello di codice in un layout lineare denominato "childLayout" come il seguente.
-- RelativeLayout
-- Linear Layout
-- TextView Textview --
-- Linear Layout
-- Linear Layout
-- TextView Textview --
-- Linear Layout
-- Linear Layout
-- TextView Textview --
-- Linear Layout
--RelativeLayout
Ma non sto ottenendo l'output desiderato. Per favore aiutami a risolvere questo problema.
Ecco il codice:
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
}
L'output è:
Sembra che i textviews hanno la priorità. Come risolvere questo.
provare ad aggiungere le vostre opinioni in un LinearLayout con orientamento verticale anziché in una RelativeLayout. –