RelativeLayout子控件之填满布局

已知三个控件上下排列,第一个与第三个控件高度确定,中间第二个控件高度要填满剩下的空间

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<!-- RelativeLayout 上下3个控件第一个控件与最后一个控件知晓高度,中间控件高度无需计算;-->
<!-- 利用android:layout_below上面的控件和android:layout_above下面控件,中间控件高度直接fillparent-->

<TextView
android:id="@+id/t1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff0000"
android:text="@string/hello_world" />

<TextView
android:id="@+id/t2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/t3"
android:layout_below="@+id/t1"
android:background="#00ff00"
android:text="@string/hello_world" />

<TextView
android:id="@+id/t3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/hello_world" />

</RelativeLayout>