我正在尝试用背景色填充 LinearLayout,但是在屏幕底部我有一个带有 ListView 的页脚,背景色覆盖了它。
代码:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="#ffffff">
<!-- Header Starts-->
<LinearLayout android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@layout/header_gradient"
android:paddingTop="5dip"
android:paddingBottom="5dip">
<!-- Logo Start-->
<ImageView android:src="@drawable/reglogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"/>
<!-- Logo Ends -->
</LinearLayout>
<!-- Header Ends -->
<!-- Footer Start -->
<LinearLayout android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="90dip"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<!-- List Starts -->
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
<!-- Footer Ends -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@id/header"
android:background="@color/blue">
</LinearLayout>
</RelativeLayout>
</ScrollView>
我知道 android:layout_width="fill_parent"
是导致问题的原因,但是当我使用 wrap_content
时它没有填充我想要的区域。
如何停止背景颜色持续到页面底部?
最佳答案
问题是 android:layout_below="@id/header"
导致 LinearLayout 与页脚重叠。尝试这样做:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@id/header"
android:layout_above="@id/footer"
android:background="@color/blue">
</LinearLayout>
我们现在也在上面对齐,这样它就不会重叠。
编辑:要记住的关键点是 RelativeLayout 和 FrameLayout 允许 View 相互重叠。还要记住,ViewGroup 的 XML 后面的 View 具有更高的 Z 顺序。如果我的建议不起作用(目前无法测试,抱歉),那么您也可以尝试在蓝色背景之后声明页脚,以查看 Z 顺序是否会显示在蓝色背景之上。
关于android - LinearLayout背景色填充整个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21556550/