在同一個Activity中要實現多種不同的佈局類型或者同種佈局類型的不同方式,就需要用到嵌套的方式來實現。
例子程序實現:
(1)整個Activity最外層採用垂直方向的LinearLayout線性佈局。
(2)套用兩個LinearLayout線性佈局,上面的是水平方向的,下面的是垂直方向的。
(3)上下的LinearLayout內各放置4個空間
- <span style="color:#339933"></span><pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_weight="1">
- <TextView
- android:text="red"
- android:gravity="center_horizontal"
- android:background="#aa0000"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:layout_weight="1"/>
- <TextView
- ...../>
- <TextView
- ...../>
- <TextView
- ...../>
- </LinearLayout>
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_weight="1">
- <TextView
- ...../>
- <TextView
- ...../>
- <TextView
- ...../>
- <TextView
- ...../>
- </LinearLayout>
- </LinearLayout></pre><span style="color:rgb(80,67,61); font-family:Arial,Helvetica,Georgia,sans-serif; font-size:14px; line-height:25px">其實就是按照設計思路中的佈局要求,直接在上層佈局中嵌套使用新的佈局即可。</span><br><br>
文章轉自:http://blog.csdn.net/wangchenggong88/article/details/6655235