【发布时间】:2014-02-12 07:11:30
【问题描述】:
在布局文件中,我有一个大小可以动态增长/缩小的 Listview。我有一个按钮 btn_rec_add,它是单击事件,我在 ListView 中添加了一个项目。我在布局文件中尝试了许多更改,但无法根据 ListView 中的项目数使按钮移动其位置。如果我将按钮保留在具有 ListView 的相同 RelativeLayout 中,那么按钮会动态移动,这正是我想要的,但在 4.3 英寸显示屏手机中添加 5 个或更多元素后我看不到按钮。如果我将按钮保留在 ListView 的 RelativeLayout 之外,则它会固定在屏幕上。
目前,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>
【问题讨论】:
标签: android xml android-listview android-linearlayout android-relativelayout