android - LinearLayout背景色填充整个页面

标签 android xml

我正在尝试用背景色填充 LinearLayout,但是在屏幕底部我有一个带有 ListView 的页脚,背景色覆盖了它。

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

代码:

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

相关文章:

javascript - 仅将 CSS 应用于与父级同一类的最内层元素

ios - 分块解析 XML 文件,无需等待 Swift 中的完整下载

android - 允许从 SD 卡读取数据

android - 如果您将此 ComposeView 添加到 AppCompatActivity,请确保您使用的是 AppCompat 版本 1.3+

c# - 使用 Schematron 进行 XML 验证

java - 将图表存储在数据库中

java - TimerHandler 每秒使用受限随机生成器

android - Activity 流程 : OnCreate called when I want to resume my activity

android - 如何使用 native react 从相机胶卷中获取随机图像?

xml - 为什么 RDF 看起来如此复杂