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

Activity 布局初步 二

2012年12月10日 ⁄ 综合 ⁄ 共 4387字 ⁄ 字号 评论关闭

这篇文章告诉我们我们还可以使用各种布局方式嵌套的方式来自定义我们的界面

Activity代码就不上了,和上一篇文章一样,没有只是实现了onCreate方法,指定布局样式文件

只看这两个布局文件

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="fill_parent"
 4     android:layout_height="fill_parent"
 5     android:orientation="vertical" >
 6 
 7     <!--
 8 android:layout_weight 这是一个比例,权重只是默认的宽度配置选项,在实际
 9 项目中,一个层的文字越多,实际占用的宽度也越大
10     -->
11 
12     <LinearLayout
13         android:layout_width="fill_parent"
14         android:layout_height="fill_parent"
15         android:layout_weight="1"
16         android:orientation="horizontal" >
17 
18         <TextView
19             android:layout_width="wrap_content"
20             android:layout_height="fill_parent"
21             android:layout_weight="1"
22             android:background="#aa0000"
23             android:gravity="center_horizontal"
24             android:text="red" />
25 
26         <TextView
27             android:layout_width="wrap_content"
28             android:layout_height="fill_parent"
29             android:layout_weight="1"
30             android:background="#00aa00"
31             android:gravity="center_horizontal"
32             android:text="green" />
33 
34         <TextView
35             android:layout_width="wrap_content"
36             android:layout_height="fill_parent"
37             android:layout_weight="1"
38             android:background="#0000aa"
39             android:gravity="center_horizontal"
40             android:text="blue" />
41 
42         <TextView
43             android:layout_width="wrap_content"
44             android:layout_height="fill_parent"
45             android:layout_weight="1"
46             android:background="#aaaa00"
47             android:gravity="center_horizontal"
48             android:text="yellow" />
49     </LinearLayout>
50 
51     <LinearLayout
52         android:layout_width="fill_parent"
53         android:layout_height="fill_parent"
54         android:layout_weight="1"
55         android:orientation="vertical" >
56 
57         <TextView
58             android:layout_width="fill_parent"
59             android:layout_height="wrap_content"
60             android:layout_weight="1"
61             android:text="row one"
62             android:textSize="18pt" />
63 
64         <TextView
65             android:layout_width="fill_parent"
66             android:layout_height="wrap_content"
67             android:layout_weight="1"
68             android:text="row two"
69             android:textSize="18pt" />
70 
71         <TextView
72             android:layout_width="fill_parent"
73             android:layout_height="wrap_content"
74             android:layout_weight="1"
75             android:text="row three"
76             android:textSize="18pt" />
77 
78         <TextView
79             android:layout_width="fill_parent"
80             android:layout_height="wrap_content"
81             android:layout_weight="1"
82             android:text="row four"
83             android:textSize="18pt" />
84     </LinearLayout>
85 
86 </LinearLayout>

 

 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="fill_parent"
 4     android:layout_height="fill_parent"
 5     android:orientation="vertical"  >
 6 
 7     <!--
 8 android:layout_weight 这是一个比例,权重只是默认的宽度配置选项,在实际
 9 项目中,一个层的文字越多,实际占用的宽度也越大
10 
11 
12 
13 
14     -->
15 
16     <LinearLayout
17         android:layout_width="fill_parent"
18         android:layout_height="fill_parent"
19         android:layout_weight="1"
20         android:orientation="horizontal" >
21 
22         <TextView
23             android:layout_width="wrap_content"
24             android:layout_height="fill_parent"
25             android:layout_weight="1"
26             android:background="#aa0000"
27             android:gravity="center_horizontal"
28             android:text="red" />
29 
30         <TextView
31             android:layout_width="wrap_content"
32             android:layout_height="fill_parent"
33             android:layout_weight="1"
34             android:background="#00aa00"
35             android:gravity="center_horizontal"
36             android:text="green" />
37 
38         <TextView
39             android:layout_width="wrap_content"
40             android:layout_height="fill_parent"
41             android:layout_weight="1"
42             android:background="#0000aa"
43             android:gravity="center_horizontal"
44             android:text="blue" />
45 
46         <TextView
47             android:layout_width="wrap_content"
48             android:layout_height="fill_parent"
49             android:layout_weight="1"
50             android:background="#aaaa00"
51             android:gravity="center_horizontal"
52             android:text="yellow" />
53     </LinearLayout>
54 
55     <LinearLayout
56         android:layout_width="fill_parent"
57         android:layout_height="fill_parent"
58         android:layout_weight="1"
59         android:orientation="horizontal" >
60 
61         <TableLayout
62             xmlns:android="http://schemas.android.com/apk/res/android"
63             android:layout_width="fill_parent"
64             android:layout_height="fill_parent"
65             android:stretchColumns="1" >
66 
67             <TableRow>
68 
69                 <TextView
70                     android:padding="3dip"
71                     android:text="row1 col1" />
72 
73                 <TextView
74                     android:gravity="center_horizontal"
75                     android:padding="3dip"
76                     android:text="row1 col1" />
77 
78                 <TextView
79                     android:gravity="right"
80                     android:padding="3dip"
81                     android:text="row1 col2" />
82             </TableRow>
83             
84               <TableRow>
85 
86                 <TextView
87                     android:padding="3dip"
88                     android:text="row2 col1" />
89 
90                 <TextView
91                     android:gravity="center_horizontal"
92                     android:padding="3dip"
93                     android:text="row2 col2" />
94             </TableRow>
95             
96         </TableLayout>
97     </LinearLayout>
98 
99 </LinearLayout>

 

 

抱歉!评论已关闭.