我有一个关于在TableLayout中不使用XML的问题。 有人已经和我一样问了,但是提供的答案一直无法帮到我。 how to set width of column dynamically in android tablelayout?宽度列动态列表布局
现在我有这个
TableLayout tl = (TableLayout) findViewById(R.id.TableLayout1);
/* Create a new row to be added. */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
/* Create a Button to be the row-content. */
Button b = new Button(this);
b.setText("Dynamic Button");
b.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
/* Add Button to row. */
tr.addView(b);
Button a = new Button(this);
a.setText("Dynamic Button");
a.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
/* Add Button to row. */
a.setGravity(2);
tr.addView(a);
但我看不出如何改变
tr.setLayoutParams
会做使得例如第一个按钮列70%的工作,另一个按钮30%
工作就像一个魅力,谢谢! –