Chinaunix首页 | 论坛 | 博客
  • 博客访问: 200744
  • 博文数量: 102
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1015
  • 用 户 组: 普通用户
  • 注册时间: 2013-06-05 16:45
文章存档

2014年(73)

2013年(29)

我的朋友

分类: Android平台

2013-12-15 16:45:50

01_10_Activity布局初步(二)
(layout间的嵌套  LinearLayout和TableLayout)
1、 LinearLayou和 LinearLayou间的嵌套
2、 LinearLayou和TableLayou间的嵌套

1、 LinearLayou和 LinearLayou间的嵌套

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns: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.           android:text="green"
  21.           android:gravity="center_horizontal"
  22.           android:background="#00aa00"
  23.           android:layout_width="wrap_content"
  24.           android:layout_height="fill_parent"
  25.           android:layout_weight="1"/>
  26.       <TextView
  27.           android:text="blue"
  28.           android:gravity="center_horizontal"
  29.           android:background="#0000aa"
  30.           android:layout_width="wrap_content"
  31.           android:layout_height="fill_parent"
  32.           android:layout_weight="1"/>
  33.       <TextView
  34.           android:text="yellow"
  35.           android:gravity="center_horizontal"
  36.           android:background="#aaaa00"
  37.           android:layout_width="wrap_content"
  38.           android:layout_height="fill_parent"
  39.           android:layout_weight="1"/>
  40.        </LinearLayout>
  41.        
  42.        
  43.     <LinearLayout
  44.         android:orientation="vertical"
  45.       android:layout_width="fill_parent"
  46.            android:layout_height="fill_parent"
  47.         android:layout_weight="1">
  48.     <TextView
  49.         android:text="row one"
  50.         android:textSize="15pt"
  51.         android:layout_width="fill_parent"
  52.         android:layout_height="wrap_content"
  53.         android:layout_weight="1"/>
  54.     <TextView
  55.         android:text="row two"
  56.         android:textSize="15pt"
  57.         android:layout_width="fill_parent"
  58.         android:layout_height="wrap_content"
  59.         android:layout_weight="1"/>
  60.     <TextView
  61.         android:text="row three"
  62.         android:textSize="15pt"
  63.         android:layout_width="fill_parent"
  64.         android:layout_height="wrap_content"
  65.         android:layout_weight="1"/>
  66.     <TextView
  67.         android:text="row four"
  68.         android:textSize="15pt"
  69.         android:layout_width="fill_parent"
  70.         android:layout_height="wrap_content"
  71.         android:layout_weight="1"/>
  72.        </LinearLayout>
  73. </LinearLayout>


点击(此处)折叠或打开

  1. package mars.layout04;

  2. import android.app.Activity;
  3. import android.os.Bundle;

  4. public class Layout04 extends Activity {
  5.     /** Called when the activity is first created. */
  6.     @Override
  7.     public void onCreate(Bundle savedInstanceState) {
  8.         super.onCreate(savedInstanceState);
  9.         setContentView(R.layout.main);
  10.         //setContentView(R.layout.second);
  11.     }
  12. }
2、 LinearLayou和TableLayou间的嵌套

点击(此处)折叠或打开

  1. //second.xml
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <LinearLayout xmlns:android=""
  4.     android:orientation="vertical" android:layout_width="fill_parent"
  5.     android:layout_height="fill_parent">
  6.     <LinearLayout
  7.         android:orientation="horizontal"
  8.         android:layout_width="fill_parent"
  9.         android:layout_height="fill_parent"
  10.         android:layout_weight="1">
  11.         <TextView
  12.             android:text="red"
  13.             android:gravity="center_horizontal"
  14.             android:background="#aa0000"
  15.             android:layout_width="wrap_content"
  16.             android:layout_height="fill_parent"
  17.             android:layout_weight="1" />
  18.         <TextView
  19.             android:text="green"
  20.             android:gravity="center_horizontal"
  21.             android:background="#00aa00"
  22.             android:layout_width="wrap_content"
  23.             android:layout_height="fill_parent"
  24.             android:layout_weight="1" />
  25.         <TextView
  26.             android:text="blue"
  27.             android:gravity="center_horizontal"
  28.             android:background="#0000aa"
  29.             android:layout_width="wrap_content"
  30.             android:layout_height="fill_parent"
  31.             android:layout_weight="1" />
  32.         <TextView
  33.             android:text="yellow"
  34.             android:gravity="center_horizontal"
  35.             android:background="#aaaa00"
  36.             android:layout_width="wrap_content"
  37.             android:layout_height="fill_parent"
  38.             android:layout_weight="1" />
  39.     </LinearLayout>


  40.     <LinearLayout
  41.         android:orientation="horizontal"
  42.         android:layout_width="fill_parent"
  43.         android:layout_height="fill_parent"
  44.         android:layout_weight="1">
  45.         <TableLayout
  46.             xmlns:android=""
  47.             android:layout_width="fill_parent"
  48.             android:layout_height="fill_parent"
  49.             android:stretchColumns="0">
  50.             <TableRow>
  51.                 <TextView
  52.                     android:text="@string/row1_column1"
  53.                     android:padding="3dip" />
  54.                 <TextView
  55.                     android:text="@string/row1_column1"
  56.                     android:padding="3dip"
  57.                     android:gravity="center_horizontal">
  58.                     </TextView>
  59.                 <TextView
  60.                     android:text="@string/row1_column2"
  61.                     android:gravity="right"
  62.                     android:padding="3dip" />
  63.             </TableRow>

  64.             <TableRow>
  65.                 <TextView
  66.                     android:text="@string/row2_column1"
  67.                     android:padding="3dip" />
  68.                 <TextView
  69.                     android:text="@string/row2_column2"
  70.                     android:gravity="right"
  71.                     android:padding="3dip" />
  72.             </TableRow>
  73.         </TableLayout>
  74.     </LinearLayout>
  75. </LinearLayout>

嵌套布局也就那么回事。


阅读(507) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~