Domanda

I have the following in my activity which successfully displays 3 columns of data (there will be up to 10 rows, thus the for loop):

for (int i=0;i<10;i++)
        {
            TableRow tr = new TableRow(this);
            TextView tv0 = new TextView(this);
            TextView tv1 = new TextView(this);
            TextView tv2 = new TextView(this);
            TableRow.LayoutParams trlp = new TableRow.LayoutParams();
            trlp.span = 3;
            trlp.weight = 1;
            tr.setLayoutParams(trlp);
            tv0.setText("" + debtName[i]);
            tv1.setText("" + debtAmount[i]);
            tv2.setText("" + debtPayment[i]);
            tr.addView(tv0);
            tr.addView(tv1);
            tr.addView(tv2);
            tl.addView(tr);
        }

I want them to be evenly weighted out as there is a title row that is hard coded in to the layout. The "trlp.weight = 1;" did not change it from when it did not exist.

What I am looking for is a way to get the tv0,tv1,tv2 TextViews to be distributed evenly (horizontally).

Also for reference, I'm running at API 12.

È stato utile?

Soluzione

you have to set the weight onto the children that are supposed to scale.

1 means 100% scaling by default, if you want 3 textvies to spread evenly set 0.33 as weight for each.

TableRow.layoutParams trlp = new LayoutParams(0, LayoutParams.MATCH_PARENT, 0.33f);
tv0.setLayoutParams(trlp);
...
tr.add(tv0);
...
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top