0

私は次のようなAndroidアプリケーションを持っています:

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

    <RelativeLayout
        android:id="@+id/toplayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.90" >
        <Button
            android:id="@+id/button_1_of_10"
            android:layout_width="70dip"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="@string/text_0x1701" />
        <Button
            android:id="@+id/button_2_of_10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignRight="@+id/button_1_of_10"
            android:layout_below="@+id/button_1_of_10"/>

        <!--Another 8 buttons-->

    <RelativeLayout
            android:id="@+id/contentpane"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/button_1_of_10" >
        </RelativeLayout>
    </RelativeLayout>

    <RelativeLayout 
        android:id="@+id/actionbuttonslayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.10">
    </RelativeLayout>
</LinearLayout>

すべてのボタンが同じ高さを維持しながら、上部からフッターまでの高さ全体(0.1の重み付きRelativeLayout)を埋めるために10個のボタンが必要です。ただし、LinearLayoutのlayout_weightに相当するものがあるかどうかを知りたいのですが、RelativeLayoutsの場合は、LinearLayoutsにネストされた重みを設定するのはパフォーマンスが悪いためです。まだ試すことがあるので、他の解決策を探しているわけではありませんが、これが可能かどうか知りたいですか?

明確にするために、私の質問は次のとおりです。RelativeLayoutに同じ高さのボタンをいくつでも配置し、同時に使用可能なすべてのスペースを埋めることはできますか?

4

1 に答える 1

1

ウェイトを使用するには、LinearLayoutを使用する必要があります。ボタンを使用して線形レイアウトを作成し、必要なスペースを確保してから、内部の各ボタンandroid:layout_height="0dp"android:layout_weight="1"

すべての重みを1に合計する必要はありません。同じ重みのアイテムが同じサイズであると考えてください。

于 2012-09-03T13:08:09.327 に答える