我有一个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.
那样不起作用。它会填充宽度,但高度被设置为零。但是,如果我将layout_alignParentBottom
更改为layout_alignBottom="@+id/im"
,那么它就会起作用(有点;这不是一个令人满意的解决方案,但至少它不再是0高度了)。
发生了什么?这是个bug吗?
RelativeLayout
的layout_height
类型不会影响其任何子元素。我的意思是它已经是非零高度,所以子元素中的match_parent
应该填充它。不幸的是,我已经尝试了你的第二个建议。没有成功。 - TimmmmFrameLayout
来包含背景视图和像你所做的那样的另一个RelativeLayout
(基本上;没有必要使用两个RelativeLayout
!)。但这似乎有点过度设计,因为似乎可以在不使用其他布局的情况下实现。 - Timmmm