我在 xml 中有空的 Tablelayout 并以编程方式添加 tablerow。
行宽总是表现出'wrap_content'我错过了什么。
layout.xml 中的表格布局
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000">
</TableLayout>
</HorizontalScrollView>
Java代码:
TableLayout mRestable= (TableLayout) findViewById(R.id.tableLayout1);
TableRow row = new TableRow(this);
TextView name_tw = new TextView(this);
name_tw.setTextSize((float) 16.8);
name_tw.setText(aName);
name_tw.setGravity(Gravity.LEFT);
name_tw.setPadding(10, 10, 10, 10);
if(aValue==null)
{
name_tw.setBackgroundColor(0xffa09f9f);
name_tw.setTextSize((float) 17.8);
name_tw.setGravity( Gravity.CENTER);
name_tw.setTypeface(Typeface.DEFAULT_BOLD);
}
row.addView(name_tw);
mRestable.addView(row,new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
如何将行设置为'fill_parent'