问题描述
我对relativelayout有一个问题,它的子级可以使用layout_below和layout_weight设置其百分比高度.
I have a problem with relativelayout where its children could use layout_below and layout_weight to set its percentage height.
例如,我们有一个相对的布局,并且在里面有三个带有textviews的线性布局.现在,我想为其中三个设置(linearlayouts)相对布局总高度的25.50,25%的高度.我该怎么办?
For example, we have a relative layout and inside of it we have three linear layouts with textviews. Now, I would like to set for three of them (linearlayouts) 25,50,25 % of height of total height of relative layout. How could I accomplish it?
我找到了> weight_sum和relativelayout的解决方案(点击),但不使用layout_below.
I found a solution for weight_sum and and relativelayout (CLICK), but it doesn't use layout_below.
我该如何解决?
我尝试在所有linearlayouts内添加其他linearlayout,但是后来我无法使用layout_below.
I tried to add additional linearlayout inside of all linearlayouts, but then I am unable use layout_below.
这是概念图片的想法:
这是我的代码:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/linlay_leftcol_notification_header" >
<LinearLayout
android:id="@+id/linlay_leftcol_clock_theday"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tv_theday"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/theday"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="@+id/linlay_leftcol_clock_thetime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linlay_leftcol_clock_theday" >
<TextView
android:id="@+id/tv_thetime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/thetime"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="@+id/linlay_leftcol_clock_thenumber_themonth_theyear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linlay_leftcol_clock_thetime" >
<TextView
android:id="@+id/tv_thenumberofday_themonth_theyear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/thenumberofday_themonth_theyear"
android:textColor="#FFFFFF" />
</LinearLayout>
</RelativeLayout>
推荐答案
尝试一下...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#ff00ff"
android:orientation="vertical">
<RelativeLayout
android:layout_weight="1"
android:background="#ffff00"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Hello 1"
android:textColor="#000000"
android:textSize="15dp" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="2"
android:background="#00ffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Hello 2"
android:textColor="#000000"
android:textSize="15dp" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:background="#ffff00"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Hello 3"
android:textColor="#000000"
android:textSize="15dp" />
</RelativeLayout>
</LinearLayout>
这篇关于RelativeLayout和高度百分比.无法使用layout_below和layout_weight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!