我有个活动
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/padding_large"
android:background="@color/dark_grey">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/filter_activities"
android:background="@drawable/filter_btn"
android:textColor="@color/white"
android:textAlignment="gravity"
android:id="@+id/show_filter_btn"
android:padding="@dimen/padding_medium"
android:gravity="center"
android:layout_gravity="center"
android:drawableRight="@drawable/ic_settings"/>
</LinearLayout>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/top" />
</LinearLayout>和onCreate --我将这个片段加载到FrameLayout中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/types_spinner" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/classes_spinner" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/venues_list" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/search" />
</LinearLayout>当我运行这个应用程序时,页面显示如下

如您所见,按钮已关闭屏幕底部。我如何更改布局,使按钮始终在底部,因此如果ListView将是可滚动的,如果需要。
发布于 2013-10-01 16:14:12
您应该将LinearLayout替换为RelativeLayout。使用android:layout_alignParentBottom="true“设置按钮,并在linearLayout中放置视图的reste。这个linearLayout应该是layout_alignParentTop,layoutAbove是您的第一个按钮:
<?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:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/search"
android:id="@+id/my_button"
android:layout_alignParentBottom="true" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="@id/my_button">
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/types_spinner" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/classes_spinner" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/venues_list" />
</LinearLayout>
</RelativeLayout>https://stackoverflow.com/questions/19120823
复制相似问题