简体   繁体   English

LinearLayout背景颜色填充整个页面

[英]LinearLayout background colour filling whole page

I'm trying to fill a LinearLayout with a background colour, however at the bottom of the screen I have a footer with a ListView, which the background colour with covering. 我试图用背景色填充LinearLayout,但是在屏幕底部,我有一个带有ListView的页脚,该背景色带有覆盖层。

http://i.imgur.com/k8CzOyJ.jpg

Code: 码:

 <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>

I understand android:layout_width="fill_parent" is what is causing the problem, but when I used wrap_content it didn't fill the area I wanted it to. 我知道android:layout_width="fill_parent"是引起问题的原因,但是当我使用wrap_content它没有填充我想要的区域。

How do I stop the background colour continuing to the bottom of the page? 如何停止背景色继续到页面底部?

The problem is that android:layout_below="@id/header" is causing the LinearLayout to overlap your footer. 问题是android:layout_below="@id/header"导致LinearLayout与页脚重叠。 Try making it like this: 尝试像这样:

<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>

Where we now align above as well so that it won't overlap. 我们现在也在上方对齐的位置,因此不会重叠。

edit: The key point to remember is that RelativeLayout and FrameLayout allow Views to overlap each other. 编辑:要记住的关键是RelativeLayout和FrameLayout允许视图彼此重叠。 Also keep in mind that Views later in XML for a ViewGroup have a higher Z-order. 还请记住,稍后使用XML的ViewGroup的View的Z顺序更高。 If my suggestion doesn't work (can't test it at the moment, sorry) then you can alternatively try to declare your footer after your blue background to see if the Z-order will show above the blue background. 如果我的建议不起作用(对不起,目前无法测试),那么您也可以尝试在蓝色背景之后声明页脚,以查看Z顺序是否会显示在蓝色背景上方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM