现在的位置: 首页 > 综合 > 正文

android中的布局–嵌套布局

2013年11月02日 ⁄ 综合 ⁄ 共 1672字 ⁄ 字号 评论关闭

在同一个Activity中要实现多种不同的布局类型或者同种布局类型的不同方式,就需要用到嵌套的方式来实现。

例子程序实现:
(1)整个Activity最外层采用垂直方向的LinearLayout线性布局。
(2)套用两个LinearLayout线性布局,上面的是水平方向的,下面的是垂直方向的。
(3)上下的LinearLayout内各放置4个空间

[java] view
plain
copy

  1. <span style="color:#339933"></span><pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7.     <LinearLayout   
  8.         android:orientation="horizontal"  
  9.         android:layout_width="fill_parent"  
  10.         android:layout_height="fill_parent"  
  11.         android:layout_weight="1">  
  12.         <TextView  
  13.           android:text="red"  
  14.           android:gravity="center_horizontal"  
  15.           android:background="#aa0000"  
  16.           android:layout_width="wrap_content"  
  17.           android:layout_height="fill_parent"  
  18.           android:layout_weight="1"/>  
  19.       <TextView  
  20.           ...../>  
  21.       <TextView  
  22.           ...../>  
  23.       <TextView  
  24.           ...../>  
  25.     </LinearLayout>  
  26.    
  27.    
  28.     <LinearLayout   
  29.         android:orientation="vertical"  
  30.         android:layout_width="fill_parent"  
  31.         android:layout_height="fill_parent"  
  32.         android:layout_weight="1">  
  33.     <TextView  
  34.         ...../>  
  35.     <TextView  
  36.         ...../>  
  37.     <TextView  
  38.         ...../>  
  39.     <TextView  
  40.         ...../>  
  41.     </LinearLayout>  
  42. </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

抱歉!评论已关闭.