1

行に3つのボタンを表示する必要があり、列に3つのボタンを表示すると、
画面に合計9つのボタンが表示されます。私はandroid:layout_weight 0.33Horizo​​ntalLinearLayoutでそれぞれに割り当てます。これはすべての画面と互換性がありますが、垂直方向にも重みを設定する必要があります。

要するに、私は9ボタンで1つの画面を作成する必要があり、それはすべての画面と互換性があるはずです。これどうやってするの?はいの場合、どのように体重を垂直に設定できますか?

4

2 に答える 2

1

行ごとに1つずつ、3つの個別のLinearLayoutを作成し、それらを垂直のLinearLayoutにカプセル化します。次に、3つのLinearLayoutに同じ重みを付けます。

擬似:

<VerticalLinearLayout>

    <HorizontalLinearLayout>
        <Button 1 /> 
        <Button 2 />
        <Button 3 />
    </HorizontalLinearLayout>

    <HorizontalLinearLayout>
        <Button 4 />
        <Button 5 />
        <Button 6 />
    </HorizontalLinearLayout>

    <HorizontalLinearLayout>
        <Button 7 />
        <Button 8 />
        <Button 9 />
    </HorizontalLinearLayout>

</VerticalLinearLayout>

VerticalLinearLayoutを除いて、すべてに3の重みを付けます。すべてのlayout_widthsとlayout_heightsがfill_parentに設定されていることを確認してください。

于 2012-07-24T21:42:02.930 に答える
0

実行可能なソース

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <Button
            android:id="@+id/btnSales"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Sales" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">
        <Button
            android:id="@+id/btnProduction"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Production" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <Button
            android:id="@+id/btnStock"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Stock" />

    </LinearLayout>
</LinearLayout>
于 2017-08-15T10:34:51.123 に答える