I am displaying a table of values in my android application, and would like the columns to be distributed evenly in terms of size , instead of sizing according to content.
Been playing around with stretchColumns but couldn't manage to figure out the right combination, Any Ideas?
I had the same problem - I always only entered one number in android:stretchColumns
, but you have to enter all columns that should be stretched. So if you have three columns, you have to write:
android:stretchColumns="0,1,2"
Or write:
android:stretchColumns="*"
Then all columns will have the same size. As a reminder, android:stretchColumns
is an attribute for the TableLayout
element.
You need to set BOTH android:layout_width="0dip"
and android:layout_weight="1"
for each view within a table row. I think this works because the weights determine the proportion of the EMPTY SPACE in the row used by the respective views, and since the width of all views is set to 0dip
, the whole row is empty space, and hence with equal weights the views are all allocated the same proportion of the WHOLE width.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With