android设置TableLayout的高度。
|
我有一个只有XML的单行(即标题行)的TableLayout。我动态添加的所有其他行。
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>
在Activity类中,我添加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));
这样,所有行都将添加到表中并填满屏幕。我要设置的是,仅查看4-5行,其他可以滚动。为此我添加了以下内容:
int tableHgt = t1.getChildAt(0).getHeight() + (rowHgt *40);
t1.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, tableHgt));
这样,除了xml中添加的标题行,我什么都看不到。我怎样才能使其高度仅看到5行,然后其他所有行都可以滚动?在TableLayout
中还添加了android:scrollbars=\"vertical\"
。
我要去哪里错了?
非常感谢您的帮助。
谢谢
没有找到相关结果
已邀请:
1 个回复
佩疵瓦
scrolltest.xml