【发布时间】:2014-02-20 13:48:16
【问题描述】:
我有一个关于不在 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% 的工作
【问题讨论】:
标签: android android-tablelayout