Android Stretch columns evenly in a TableLayout

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.