I have a TableLayout with just a single row (i.e. the Header Row) in XML. Other all rows I add dynamically.
XML PART :
<TableLayout android:id="@+id/list_table"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:stretchColumns="1" android:background="#808000" **android:scrollbars="vertical">**
<TableRow android:layout_margin="1dp" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/list_head_Row">
<TextView android:layout_width="wrap_content"
android:text="Col1" android:layout_height="wrap_content"></TextView>
<TextView android:gravity="center" android:layout_width="wrap_content" android:text="Col2" android:layout_height="wrap_content"></TextView>
<TextView android:layout_width="wrap_content" android:text="Col3" android:layout_height="wrap_content"></TextView>
</TableRow>
</TableLayout>
In Activity class, I add TableRows :
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
// Add 3 TextViews
// Add Row to table
t1.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
With this much all rows gets added to the table and fills the screen. I want to set is, view only 4-5 rows and others can be scrolled.For that I added :
int tableHgt = t1.getChildAt(0).getHeight() + (rowHgt *40);
t1.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, tableHgt));
With this I can’t see any row at all except the header row added in xml. How can I make its height to see just 5 rows and othe all can be scrolled ? In TableLayout android:scrollbars="vertical" is also added.
Where am I going wrong ?
Any help is highly appreciated.
Thanks
why don’t you use ListView ?
but ok … back to your question
put TableLayout in ScrollView and setup height in ScrollView
EDIT: code
activity.java
scrolltest.xml