在同一个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