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 に答える