Android将所有布局元素保留在屏幕上
我在一个相对论中有一个片段。该片段包含一个ListView和一个按钮,并在另一个布局下面加载和显示。片段并不总是可见的,并且每次显示时ListView中的数据都会更改 除了一件事,一切都很好。如果屏幕空间太小,ListView高度会缩小(正确),但按钮不会显示。它刚被砍掉。我在整个片段布局周围有一个边框,可以一直正确显示,但是如果没有足够的空间,按钮就会消失,边框会正确显示在ListView周围 我怎样才能让我的按钮也保持在屏幕上,而只是缩小ListView?我的片段布局是:Android将所有布局元素保留在屏幕上,android,android-layout,listview,android-fragments,Android,Android Layout,Listview,Android Fragments,我在一个相对论中有一个片段。该片段包含一个ListView和一个按钮,并在另一个布局下面加载和显示。片段并不总是可见的,并且每次显示时ListView中的数据都会更改 除了一件事,一切都很好。如果屏幕空间太小,ListView高度会缩小(正确),但按钮不会显示。它刚被砍掉。我在整个片段布局周围有一个边框,可以一直正确显示,但是如果没有足够的空间,按钮就会消失,边框会正确显示在ListView周围 我怎样才能让我的按钮也保持在屏幕上,而只是缩小ListView?我的片段布局是: <Relat
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/quickFilterLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66000000">
<ImageView
android:id="@+id/quickFilterArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/quick_filter_top_arrow"
android:contentDescription="quick filter up arrow" />
<RelativeLayout
android:id="@+id/quickFilterMainContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_below="@id/quickFilterArrow"
android:background="@drawable/quick_filters_background" >
<ListView
android:id="@+id/quickFilterListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#C8C7CC"
android:dividerHeight="1dp" />
<Button
android:id="@+id/closeQuickFilterButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/quickFilterListView"
android:background="@drawable/quick_filter_close_button_selector"
android:text="Close" />
</RelativeLayout>
</RelativeLayout>
那么:
<?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="wrap_content" >
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"/>
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/button" />
</RelativeLayout>
这使得您的按钮占据了40dp,而listview占据了所有其他内容。最好为布局分配权重。listview只是不理解换行内容,请始终填充整个屏幕,尝试在listview中添加上面的布局=@+id/closeQuickFilterButton。此外,删除=“@id/quickFilterListView”下面的布局_以避免循环依赖。