在布局资源 XML 中,我有 3 个relativelayout,它们位于主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>
I set weight=1
and layout_width=0dp
对于每个relativeLayout并且此技术适用于按钮,我认为relativeLayout也同样如此,看来我的想法是错误的。任何想法?
UPD1:我添加了我想要的图像
RelativeLayout
不注意android:layout_weight
。 (这是一个属性LinearLayout.LayoutParams http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html,但不属于RelativeLayout.LayoutParams http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html.)
您应该能够通过更简单的视图层次结构获得所需的布局。自最后两个以来,尚不清楚您要做什么RelativeLayout
s 为空。如果您需要纯粹的垂直组织,我建议使用LinearLayout
代替RelativeLayout
.
EDIT根据您的编辑,您似乎需要三个复合视图的水平布局,每个视图都可单击。我认为像下面这样的东西会起作用:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- First column -->
<LinearLayout
android:id="@+id/firstColumn"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="..." />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="text 1"
. . . />
</LinearLayout>
<!-- Second column -->
<LinearLayout . . . >
. . .
</LinearLayout>
</LinearLayout>
如果按钮内容不正确,可以更换二级按钮LinearLayout
意见与RelativeLayout
如果这有助于更好地组织布局。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)