如何让`View`填充`RelativeLayout`?

Tim*_*mmm 9 layout android view relativelayout

我有RelativeLayout一些东西,我想要一个背景视图来填补整个事情.这是我期望的工作:

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#000" >

            <View
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:layout_alignParentBottom="true"
                android:layout_margin="1px"
                android:background="#fafafa" />

            <ImageView
                android:id="@+id/im"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:src="@drawable/ic_blank_profile" />

        .... and so on.
Run Code Online (Sandbox Code Playgroud)

这不起作用.它填充宽度但高度设置为零.但是,如果我layout_alignParentBottom改为layout_alignBottom="@+id/im"那么它确实有效(有点;这不是一个令人满意的解决方案,但至少它不再是0高度).

这是怎么回事?这是一个错误吗?

Rol*_*f ツ 2

尝试将layout_height相对布局的属性设置为match_parent

如果alignParent从视图中删除所有属性并仅使用match_parent视图的宽度和高度,会发生什么情况?

罗尔夫

最终编辑?:

小例子,像这样吗?使用容器?当内部RelativeLayout的内容增长时,View将随之拉伸。

<?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:layout_height="match_parent"
    android:orientation="vertical" >


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >


        <View
            android:id="@+id/view1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignBottom="@+id/relativeLayout1"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_margin="1px"
            android:background="#fafafa" />

        <RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/im"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:src="@drawable/ic_blank_profile" />
        </RelativeLayout>
    </RelativeLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)