0

私はまさに私が望むことを行うXMLのテーブルレイアウトを持っています:

<TableRow  android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/evenrow">
<TextView android:text="Check" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_weight="1"></TextView>

プログラムでテーブル行を追加しようとしていますが、layout_weight セットを取得できないようです。Javaコードは次のとおりです。

TableRow.LayoutParams trlayout = new TableRow.LayoutParams (TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1);
TableLayout.LayoutParams tablelayout = new TableLayout.LayoutParams (TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.FILL_PARENT);
TableRow tr = new TableRow(this);
    tr.setLayoutParams(trlayout);
    TextView check = new TextView(this);
    check.setText(String.format("%5.2f", i)); 
    tr.addView(check);

new TableRow.LayoutParams の 3 番目のパラメーターが行の子のデフォルトの重みだと思っていましたが、機能していません。私は何が欠けていますか?

4

1 に答える 1

4

通常の XML では、wrap_content展開する方向のディメンションを設定すると、レイアウトの重みは影響しません。

幅パラメータを「0dp」に変更すると、レイアウトの重みが機能するはずです。

于 2012-05-14T03:32:14.327 に答える