我有一个 XML 格式的表格布局,它完全符合我的要求:
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/evenrow">
<TextView android:text="Check" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_weight="1"></TextView>
我正在尝试以编程方式添加表格行,但我似乎无法设置 layout_weight 。这是java代码:
TableRow.LayoutParams trlayout = new TableRow.LayoutParams (TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1);
TableLayout.LayoutParams tablelayout = new TableLayout.LayoutParams (TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.FILL_PARENT);
TableRow tr = new TableRow(this);
tr.setLayoutParams(trlayout);
TextView check = new TextView(this);
check.setText(String.format("%5.2f", i));
tr.addView(check);
我认为 new TableRow.LayoutParams 的第三个参数是该行子级的默认权重,但它不起作用。我错过了什么?