标签:
在此之前,相信大家都已经对Android API所提供的布局方式非常熟悉了。也许在接触Android的时候都有过这样的想法,如果可以按照百分比的方式进行界面布局,这样适配各种屏幕就简单多了吧!!以前的一个小梦想,现在终于得以实现,谷歌正式提供百分比布局支持库(percent-support-lib)。
获取支持库:
1
2
3
4
5
|
dependencies { compile ‘com.android.support : percent : 22.2 . 0 ‘ } |
新的布局组件:
新的属性设置:
使用介绍:
1
|
xmlns:app="http://schemas.android.com/apk/res-auto" |
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
|
< android.support.percent.PercentFrameLayout android:layout_width = "match_parent" android:layout_height = "match_parent" /> < ImageView app:layout_widthPercent = "50%" app:layout_heightPercent = "50%" app:layout_marginTopPercent = "25%" app:layout_marginLeftPercent = "25%" /> </ android.support.percent.PercentFrameLayout /> |
01
02
03
04
05
06
07
08
09
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
88
89
90
91
92
93
94
95
96
97
98
99
|
< android.support.percent.PercentRelativeLayout android:layout_width = "match_parent" android:layout_height = "match_parent" > < View android:id = "@+id/top_left" android:layout_width = "0dp" android:layout_height = "0dp" android:layout_alignParentTop = "true" android:background = "#ff0000" app:layout_heightPercent = "30%" app:layout_widthPercent = "70%" /> < View android:id = "@+id/top_right" android:layout_width = "0dp" android:layout_height = "0dp" android:layout_alignParentTop = "true" android:layout_toRightOf = "@+id/top_left" android:background = "#00ff00" app:layout_heightPercent = "30%" app:layout_widthPercent = "30%" /> < View android:id = "@+id/centre" android:layout_width = "match_parent" android:layout_height = "0dp" android:layout_below = "@+id/top_left" android:background = "#0000ff" app:layout_marginLeftPercent = "10%" app:layout_marginRightPercent = "20%" app:layout_marginTopPercent = "10%" app:layout_marginBottomPercent = "10%" app:layout_heightPercent = "40%" /> < View android:layout_width = "match_parent" android:layout_height = "0dp" android:id = "@+id/bottom" android:layout_below = "@+id/centre" android:background = "#00f0ff" android:layout_alignParentLeft = "true" android:layout_alignParentStart = "true" app:layout_heightPercent = "10%" /> </ android.support.percent.PercentRelativeLayout > |
1、layout_marginTopPercent这种类型的参数具体的意义是什么?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
|
< View android:id = "@+id/centre" android:layout_width = "match_parent" android:layout_height = "0dp" android:layout_below = "@+id/top_left" android:background = "#0000ff" app:layout_marginLeftPercent = "10%" app:layout_marginRightPercent = "20%" app:layout_marginTopPercent = "10%" app:layout_marginBottomPercent = "10%" app:layout_heightPercent = "40%" /> |
2、控件设置的百分比是相对于屏幕还是相对于父容器而言呢?
1
2
3
4
5
6
7
8
9
|
< android.support.percent.PercentRelativeLayout android:layout_width = "match_parent" android:layout_height = "300dp" > |
1
2
3
4
5
6
7
8
9
|
< android.support.percent.PercentRelativeLayout android:layout_width = "200dp" android:layout_height = "match_parent" > |
Android百分比布局支持库介绍——com.android.support:percent
标签:
原文地址:http://www.cnblogs.com/haobadea/p/4735980.html