close

每一個人第一次接觸到Android UI 設計時,第一個認識的ViewGroup應該都是LinearLayout,因為eclipse自動新增的專案預設就是以「android.widget.LinearLayout 」為主要的版面布局。
LinearLayout是以你設定它的「android:orientation」屬性;值有:垂直(vertical)或水平(horizontal)兩種,用來排列所有的子元件。所有的子元件都被線性堆放在其它元素之後,因此一個設定垂直屬性的每一列只會有一個元件一直向下排列,而不管他們有多寬;而一個設定水平屬性的每一行只有一個元件一直向右排列(高度為最高子元件的高度加上邊框高度)。LinearLayout保持子元件之間的間隔以及互相對齊。
|
LinearLayout常用屬性
|
|
|
屬性名稱
|
描述
|
|
LinearLayout佈局的方向,可取horizontal(水平)和vertical(垂直)兩種排列方式
|
|
|
內部元件對於父元件的對齊方式
|
|
|
元件的分配大小的權值,數字越大分配越多
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ff0" android:orientation="vertical" > <Button android:id="@+id/Button15" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" android:text="靠左" /> <Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:text="離左邊界30dp" /> <Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="靠右" /> <Button android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="置中" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:background="#cc0" android:orientation="horizontal" > <Button android:id="@+id/Button14" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/Button11" android:layout_width="wrap_content" android:layout_height="80dp" android:text="以我為列高" /> <LinearLayout android:layout_width="100dp" android:layout_height="match_parent" android:background="#f0f" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/Button16" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> <Button android:id="@+id/Button17" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout> </LinearLayout></LinearLayout> |
全站熱搜
留言列表