我想要动态地创建的TableRow
对象,并将它们添加到 TableLayout
。
该的TableRow
对象有2个项目,一个的TextView
和复选框
。该的TextView
的项目需要有自己的布局权值设置为1推复选框
项目的最右边。
I'm trying to dynamically create TableRow
objects and add them to a TableLayout
.
The TableRow
objects has 2 items, a TextView
and a CheckBox
. The TextView
items need to have their layout weight set to 1 to push the CheckBox
items to the far right.
我无法找到如何编程设置的TextView
项目的布局重量的文档。
I can't find documentation on how to programmatically set the layout weight of a TextView
item.
您必须使用 TableLayout.LayoutParams
像这样的东西:
You have to use TableLayout.LayoutParams
with something like this:
TextView tv = new TextView(v.getContext());
tv.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));
的最后一个参数是重
The last parameter is the weight.