【发布时间】:2012-12-10 03:51:21
【问题描述】:
在布局资源 XML 中,我有 3 个 RelativeLayout(s),它们位于主 RelativeLayout 中。视图将垂直显示。这 3 个 RelativeLayout() 彼此相邻设置,我希望它们填满整个屏幕,不管屏幕大小是多少。我的,布局视图:
<RelativeLayout 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:background="@drawable/backg"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/top_mr_image"
android:src="@drawable/temp" />
<RelativeLayout
android:id="@+id/r1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imageView1"
android:layout_marginLeft="10dp"
android:background="@drawable/r1bg"
android:layout_weight="1"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="@dimen/txt_mr_right"
android:layout_marginRight="@dimen/txt_mr_right"
android:layout_marginTop="39dp"
android:text="S"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/textView1"
android:layout_marginLeft="@dimen/txt_mr_right"
android:layout_marginRight="@dimen/txt_mr_right"
android:text="T"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/r2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignTop="@+id/r1"
android:layout_toRightOf="@+id/r1"
android:layout_weight="1" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/r3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignTop="@+id/r2"
android:layout_toRightOf="@+id/r2"
android:layout_weight="1" >
</RelativeLayout>
我为每个 relativeLayout 设置了 weight=1 和 layout_width=0dp,并且这种技术适用于按钮,我认为 relativeLayout 也是如此,看来我的想法是错误的。有什么想法吗?
UPD1:我添加了一张我想要的图片
【问题讨论】:
-
我已经完成了我想要的工作,感谢 cmets
-
请作为答案分享。很多好奇的小伙伴都想知道你是怎么做到的。
-
请检查您的问题。它可能会误导读者,您希望
FrameLayout作为一个组视图,您希望图像的子级RelativeLayout将一个覆盖在另一个之上。但是,FYKI,如果您也可以使用RelativeLayout实现这种覆盖,如果它的所有子项在layout_width和layout_height上都有 match_parent 而没有指定彼此之间的关系。方向和权重是LinearLayout的属性。