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?
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.
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:
TableLayout
fits the entire parent view on a large screen deviceyou 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>
This worked for me..
tableLayout.setColumnShrinkable(1,true);
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