0

2つのボタンの後ろに表示されているListViewがあります。ListViewでボタンの下の領域を埋めてほしいのですが。私はこのリンクの解決策を試しました: ListViewとボタンを備えたAndroidレイアウトと下のボタンを備えたListviewが正しく機能していません。ただし、動作していません。ListViewをボタンの下に保持する方法を教えてください。

ここに画像の説明を入力してください

これが私のコードです:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1.0"
    >

    <ListView
        android:id="@+id/listview"
        android:layout_width="fill_parent"
           android:layout_below="@id/layoutButtons"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:weightSum=".50"  />

        <LinearLayout
 android:id="@+id/layoutButtons"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
           android:layout_weight="1.0" >

        <Button
            android:id="@+id/btnLogout"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".70"
            android:text="left" />

        <Button
            android:id="@+id/btnMessage"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".30"
            android:text="right" />
    </LinearLayout>

</RelativeLayout>
4

3 に答える 3

1

次のことを試してください。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    >

        <LinearLayout
 android:id="@+id/layoutButtons"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
           android:orientation="horizontal" >

        <Button
            android:id="@+id/btnLogout"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".70"
            android:text="left" />

        <Button
            android:id="@+id/btnMessage"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".30"
            android:text="right" />
    </LinearLayout>

    <ListView
        android:id="@+id/listview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</RelativeLayout>

お役に立てれば。

于 2012-09-28T17:11:42.650 に答える
1

リストビューのヘッダーにボタンを追加できます。

ボタン listview_header.xmlを使用してレイアウトを作成します

   <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layoutButtons"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
       android:layout_weight="1.0" >

    <Button
        android:id="@+id/btnLogout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".70"
        android:text="left" />

    <Button
        android:id="@+id/btnMessage"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".30"
        android:text="right" />
</LinearLayout>     

ビューを宣言する:

 private ListView listView;
 private ViewGroup mListHeaderView;

onCreateView()

 mListHeaderView = (ViewGroup)inflater.inflate(R.layout.listview_header,
 listView, false);

onActivityCreated()

listView = this.getListView();
listViewTickets.addHeaderView(mListHeaderView,null,false);
于 2012-09-28T17:28:34.557 に答える
1

レオアの答えを少し修正しました:

<LinearLayout
    android:id="@+id/layoutButtons"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1.0" >

    <Button
        android:id="@+id/btnLogout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".70"
        android:text="left" />

    <Button
        android:id="@+id/btnMessage"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".30"
        android:text="right" />
</LinearLayout>

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/layoutButtons"
    android:weightSum=".50" />

を削除しました

android:layout_alignParentTop="true"

ListViewから、ListViewのIDを@ android:id/listに変更しました。また、ListViewはボタンを使用してLinearLayoutの下に配置する必要があります。そうしないと、ListViewでandroid:layout_belowを使用できなくなります。

于 2012-09-28T17:37:24.680 に答える