Android TableLayout Width

The pragmatic way to solve this is to use the stretchColumns and shrinkColumns attributes in TableLayout. Their values should be 0-based indexes of columns.

For example, if you have a two column Table layout and:

  • You would like the second column to fill up with empty space (stretch) so the TableLayout fits the entire parent view on a large screen device
  • You would like the first column to be shrunk (and its contents possibly wrapped / ellipsized) on a small screen device

you would define your TableLayout as:

<TableLayout
    android:id="@+id/my_table_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1"
    android:shrinkColumns="0" >
</TableLayout>

You may want to define the sizes of the columns by using a weight. So you will define the table layout height to fill parent but for each column you should set the width to "0px" and the weight to the percentage you want the column to span. So assuming you want the first column to be 30% of the screen width you set it's weight to "0.3" and the second column to "0.7".

Try it and see if that works.