Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Stretch columns evenly in a TableLayout

Tags:

android

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?

like image 260
Drahcir Avatar asked Nov 03 '09 11:11

Drahcir


2 Answers

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.

like image 184
Simon Avatar answered Oct 01 '22 17:10

Simon


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.

like image 20
linitbuff Avatar answered Oct 01 '22 18:10

linitbuff