Android TableLayout Width

Sameer Segal picture Sameer Segal · Oct 30, 2010 · Viewed 65.5k times · Source

I have a two column TableLayout as the only child of a scroll view. The first column contains TextViews ('labels') and the second column contains EditText/Spinner/DateWidget etc ('values'). Even though I have have specified android:layout_width="fill_parent" for TableLayout, TableRow & all widgets (in 'values' column).

The screen looks perfect when the activity is created. However, when one types a really long value in the EditText, the 'values' column goes beyond the visible screen area.

How do I tackle this?

Answer

Savvas Dalkitsis picture Savvas Dalkitsis · Oct 30, 2010

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.