0

我需要使用代码动态生成表格布局。我无法让它显示。我已将表格生成代码段缩减为基本内容,以尝试将其弄清楚,但即使是这个大大简化的版本也无法正常工作(即不显示)。有人可以指出我做错了什么吗?谢谢。

public class TableByCodeTest extends Activity{

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TableLayout tableLayout = new TableLayout(this);
    tableLayout.setLayoutParams(
        new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    TableRow firstTableRow = new TableRow(this);
    firstTableRow.setLayoutParams(
        new TableRow.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
    TextView title = new TextView(this);
    title.setText(R.string.title);
    title.setLayoutParams(
        new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

    firstTableRow.addView(title);
    tableLayout.addView(firstTableRow);
    setContentView(tableLayout);

    }
}
4

1 回答 1

2

换行:

firstTableRow.addView(title);

firstTableRow.addView(title,new TableRow.LayoutParams(0));

将其添加到第 0 行。

于 2010-08-26T12:51:34.033 回答