在佈局文件中,我有一個ListView,其大小可以動態增長/縮小。我有一個按鈕btn_rec_add,它是單擊事件我在ListView中添加一個項目。我已經嘗試了佈局文件中的許多更改,但無法使按鈕根據ListView中的項目數量來移動其位置。如果我將按鈕放在與ListView相同的RelativeLayout中,則按鈕動態移動,這正是我想要的,但在4.3英寸顯示屏手機中添加5個或更多元素後,我看不到按鈕。如果我將按鈕保持在ListView的RelativeLayout之外,則它固定在屏幕上。如何使按鈕的位置基於ListView中項目的數量移動
當前,btn_rec_add固定在佈局的底部。有人可以幫我解決這個問題。
下面是XML代碼:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg" >
<ImageView
android:id="@id/top_bar_view"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/top_bar"
android:contentDescription="@string/content" />
<TextView
android:id="@+id/txt_recipients"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:padding="8dp"
android:text="@string/text_recipients"
android:textColor="#FFFFFF"
android:textSize="16sp" />
<ImageButton
android:id="@id/btn_back"
android:layout_width="80dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:contentDescription="@string/content"
android:paddingTop="6dp"
android:src="@drawable/ic_back" />
<RelativeLayout
android:id="@+id/Rlayout_recipients"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/btn_rec_add"
android:layout_alignParentLeft="true"
android:layout_below="@id/top_bar_view" >
<ListView
android:id="@+id/rec_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:dividerHeight="0dp"
android:paddingTop="20dp" />
</RelativeLayout>
<ImageButton
android:id="@+id/btn_rec_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:contentDescription="@string/content"
android:src="@drawable/icon_add" />
</RelativeLayout>
太棒了!它的作用就像一個魅力:)謝謝:) – user2688158
請確保你瞭解'LinearLayout'發生了什麼。他們是非常有用的佈局!如果您從中瞭解到這一點並解決您的問題,請繼續並提升它的評分:http://meta.stackexchange.com/a/198551/187616 –