0

ここで明らかな何かが欠けている可能性がありますが、これを理解できないようです。1、5、または 6 のような結果を探しています。これは、画面の幅を満たす 3 つの均等に配置されたボタンの 1 つの行です。残念ながら、これらの方法にはそれぞれ何か問題があるようです。1 は「この TableRow レイアウトまたはその TableLayout 親はおそらく役に立たない」という警告を出し、5 と 6 は「ネストされた重みはパフォーマンスに悪い」という警告を出します。だから基本的に、これを行うための最良の方法は何だろうと思っています。No.1の警告を無視するか、TableRowまたはTableLayoutだけで正しく表示することができますか

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" >

<!-- No.1 -->
<TableLayout android:id="@+id/tableLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="*" >
    <TableRow android:id="@+id/tbRow0" android:layout_width="wrap_content" android:layout_height="wrap_content" >
        <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/num1" />
        <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/num2" />
        <Button android:id="@+id/btn3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/num3" />
    </TableRow>
</TableLayout>

<!-- No.2 -->
<TableRow android:id="@+id/tbRow1" android:layout_width="fill_parent" android:layout_height="wrap_content" >
    <Button android:id="@+id/btn4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/num1" />
    <Button android:id="@+id/btn5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/num2" />
    <Button android:id="@+id/btn6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/num3" />
</TableRow>

<!-- No.3 -->
<TableRow android:id="@+id/tbRow2" android:layout_width="fill_parent" android:layout_height="wrap_content" >
    <Button android:id="@+id/btn7" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/num1" />
    <Button android:id="@+id/btn8" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/num2" />
    <Button android:id="@+id/btn9" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/num3" />
</TableRow>

<!-- No.4 -->
<TableRow android:id="@+id/tbRow3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="*" >
    <Button android:id="@+id/btn10" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/num1" />
    <Button android:id="@+id/btn11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/num2" />
    <Button android:id="@+id/btn12" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/num3" />
</TableRow>

<!-- No.5 -->
<TableRow android:id="@+id/tbRow4" android:layout_width="fill_parent" android:layout_height="wrap_content" >
    <Button android:id="@+id/btn13" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/num1" />
    <Button android:id="@+id/btn14" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/num2" />
    <Button android:id="@+id/btn15" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/num3" />
</TableRow>

<!-- No.6 -->
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" >
    <Button android:id="@+id/btn16" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/num1" />
    <Button android:id="@+id/btn17" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/num2" />
    <Button android:id="@+id/btn18" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/num3" />
</LinearLayout>

<!-- No.7 -->
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" >
    <Button android:id="@+id/btn19" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/num1" />
    <Button android:id="@+id/btn20" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/num2" />
    <Button android:id="@+id/btn21" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/num3" />
</LinearLayout>

</LinearLayout>
4

2 に答える 2

1

5 が正しいと思います。さらに、ネストされた重みの警告が表示されません。

アガルワルの指摘に関係しているのかもしれません。

編集:申し訳ありませんが、5はLinearLayoutを使用していました。つまり、次のとおりです。

<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" >
    <Button android:id="@+id/btn13" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/num1" />
    <Button android:id="@+id/btn14" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/num2" />
    <Button android:id="@+id/btn15" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/num3" />
</LinearLayout>
于 2012-04-26T02:52:00.073 に答える
0

最初の行の後のxmlファイルでは、tablelayoutを閉じていますが、2,5行のテーブル行を使用している場合でも問題になる可能性があります。

1つだけ必要な場合は、線形レイアウトを使用することをお勧めします。これは、小さなxmlファイルで問題がないため、パフォーマンスが悪くないためです。

于 2012-04-26T02:38:38.880 に答える