0

ListView上部に 1 つ、下部に複数のレイアウトを表示する方法Buttons(写真のように)

ここに画像の説明を入力

以下は私が試したコードです(問題は、ボタンの後ろに多少見えるリストにボタンが重なっているということです.3つのボタンのサイズは等しくありませんが、重量の合計を使用しました):

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:weightSum="3" >

        <Button
            android:id="@+id/bDone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Done" />

        <Button
            android:id="@+id/bCancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Cancel" />

        <Button
            android:id="@+id/bSelAll"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Select All" />
    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >
    </ListView>

</RelativeLayout>
4

2 に答える 2

7

私がしたことは、基本的にリスト用に 1 つ、ボタン用に 1 つの 2 つの線形レイアウトを行うことです。また、重み = 1 と幅 = 0 を設定すると、同じサイズになります。このコードは私にとってはうまくいきました:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<LinearLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginTop="5dip"  
    android:layout_marginBottom="5dip"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_above="@+id/footerlayout"
    android:id="@+id/listviewlayout">
    <ListView
        android:id="@+id/list"               
        android:layout_width="fill_parent"               
        android:layout_height="wrap_content"  
        android:layout_weight="1">
    </ListView> 
 </LinearLayout>
 <LinearLayout android:id="@+id/footerlayout"
        android:layout_marginTop="3dip"
        android:layout_height="45dip"
        android:orientation="horizontal" 
        android:layout_width="fill_parent" 
        android:gravity="center"
        android:layout_alignParentBottom="true">
        <Button
            android:id="@+id/bDone" 
            android:text="Done" 
            android:layout_width="0dip"
            android:layout_height="40dip"
            android:layout_weight="1">
        </Button>   
        <Button
            android:id="@+id/bCancel" 
            android:text="Cancel"
            android:layout_width="0dip"
            android:layout_height="40dip"
            android:layout_weight="1"   
            >
        </Button>   
        <Button
            android:id="@+id/bSelAll" 
            android:text="Select All"
            android:layout_width="0dip"
            android:layout_height="40dip"
            android:layout_weight="1"
            >
        </Button>   
    </LinearLayout>
</RelativeLayout>
于 2012-07-09T21:37:41.873 に答える
0

LinearLayoutid プロパティに追加し、これをListView

android:layout_above="@id/linear_layout_id"

ボタンのプロパティで同じサイズの変更を行うには、これを行います

android:layout_width="wrap_content"

これに

android:layout_width="match_parent"
于 2012-07-09T21:17:07.060 に答える