0

私はこのようにUIを設計しようとしています: ここに画像の説明を入力

問題は、ListView を追加してその幅を match_parent に設定すると、ルート レイアウトが使用され、別のレイアウトにラップされていても画面全体の幅が使用され、幅の 1/4 しか使用されないことです。誰かが絵に描かれたものを達成する方法を教えてもらえますか? また、ネストされた layout_weight はパフォーマンスに悪いと読みましたが、まったく別のものを使用する必要がありますか?

XML ファイル:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="horizontal" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="3"> 
    </RelativeLayout>

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" 
            android:layout_weight="13">

            <ListView
                android:id="@+id/listView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </ListView>

        </LinearLayout>

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

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />

        </LinearLayout>

    </LinearLayout>

</LinearLayout>
4

2 に答える 2

1

ViewGroup数が少ない割に が多すぎるようですView。この部分を変更できる可能性があります

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:layout_weight="13">

        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>

    </LinearLayout>

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

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

    </LinearLayout>

のようなものに

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

        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

    </LinearLayout>

余分なものは必要ないと思いLinearLayoutます。またはなどの特定のプロパティが必要な場合は、これLinearLayoutを に変更することもできます。RelativeLayoutButtonlayout_alignParentBottomlayout_above

于 2013-10-16T18:43:54.273 に答える
0

右側のビューを に変更しRelativeLayout、ボタンを右側のビューの下部に設定してから、プロパティ android:layout_above="@id/button1"を設定すると、ボタンが占めていない残りのスペースを埋めるListViewことができます。ListViewまた、あなたが持っていた不要なネストされたレイアウトをたくさん削除しました。

レイアウト ウェイトを使用する場合は、 の向きに応じて幅/高さを 0dip に指定する必要があることを忘れないでくださいLinearLayout。これが、ListView が画面全体を占有していた理由である可能性があります。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="horizontal" >

    <RelativeLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="3" />

    <RelativeLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="Button" />

        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@id/button1" />
    </RelativeLayout>

</LinearLayout>
于 2013-10-16T18:41:55.250 に答える