百分比布局方案对比

本文最后更新于:1 年前

Reference


设计图示例


标注

有时候从设计那里拿到的直接是 psd 文件,打开后是这样的:

也就是未加任何标注,仅提供可供导出图片的图层,这对写布局基本没有帮助
我需要的至少是这样的:


稍微调整设计图便于写布局

设置全部内容的 padding

统一高度近似的分隔部分

统一高度近似的输入部分

统一宽度近似的输入类型部分

ConstraintLayout

布局

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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg">

<View
android:id="@+id/view_top"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.051056338028169"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/view_left"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.0625" />

<View
android:id="@+id/view_right"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.0625" />

<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:src="@drawable/logo"
app:layout_constraintHeight_percent="0.1707746478873239"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_top" />

<View
android:id="@+id/view_2"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0352112676056338"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/logo" />

<TextView
android:id="@+id/flatte"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:gravity="center"
android:includeFontPadding="false"
android:letterSpacing="1"
android:text="FLATTE"
android:textColor="#ffffff"
android:textStyle="bold"
app:layout_constraintHeight_percent="0.0387323943661972"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_2" />

<View
android:id="@+id/view_3"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0352112676056338"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/flatte" />

<TextView
android:id="@+id/socail_app"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:gravity="center"
android:includeFontPadding="false"
android:letterSpacing="0.1"
android:text="SOCAIL APP"
android:textColor="#fff048"
android:textStyle="bold"
app:layout_constraintHeight_percent="0.0140845070422535"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_3" />

<View
android:id="@+id/view_4"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0889084507042254"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/socail_app" />

<android.support.constraint.ConstraintLayout
android:id="@+id/container_user"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0440140845070423"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_4">

<RelativeLayout
android:id="@+id/user_icon"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.1125">

<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="@drawable/user_icon" />
</RelativeLayout>

<android.support.constraint.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/user_icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/form_user"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="#8f9399"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />

<EditText
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@null"
android:gravity="center_vertical"
android:hint="USERNAME OR EMAIL"
android:textColorHint="#ffffff"
app:layout_constraintBottom_toTopOf="@id/form_user"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>

<View
android:id="@+id/view_5"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0352112676056338"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/container_user" />

<android.support.constraint.ConstraintLayout
android:id="@+id/container_password"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0440140845070423"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_5">

<RelativeLayout
android:id="@+id/password_icon"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.1125">

<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="@drawable/password_icon" />
</RelativeLayout>

<android.support.constraint.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/password_icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/form_password"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="#8f9399"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />

<EditText
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@null"
android:gravity="center_vertical"
android:inputType="textPassword"
android:text="password"
android:textColorHint="#ffffff"
app:layout_constraintBottom_toTopOf="@id/form_password"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>

<View
android:id="@+id/view_6"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0352112676056338"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/container_password" />


<TextView
android:id="@+id/login"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/bg_login"
android:gravity="center"
android:text="LOGIN"
android:textColor="#434a54"
android:textStyle="bold"
app:layout_constraintHeight_percent="0.0809859154929577"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_6" />

<View
android:id="@+id/view_7"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0352112676056338"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/login" />

<TextView
android:id="@+id/forget_password"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:gravity="center"
android:includeFontPadding="false"
android:text="FORGET PASSWORD"
android:textColor="#fcfcfc"
android:textStyle="bold"
app:layout_constraintHeight_percent="0.0140845070422535"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_7" />

<View
android:id="@+id/view_8"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0352112676056338"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/forget_password" />

<TextView
android:id="@+id/register"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/bg_register"
android:gravity="center"
android:text="REGISTER"
android:textColor="#ffee58"
android:textStyle="bold"
app:layout_constraintHeight_percent="0.0809859154929577"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_8" />

<View
android:id="@+id/view_9"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0352112676056338"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/register" />

<LinearLayout
android:id="@+id/container_login_with_third_part_center"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0845070422535211"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_9">

<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/facebook" />

<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/twitter" />

<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/google" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>

效果

设备|9.6吋 1280x800(mdpi)的荣耀畅玩平板2 真机|4吋 800x480(hdpi)的谷歌NexusS 模拟器|5.65吋 1440x720(xhdpi)的荣耀9Lite 真机| 5.5吋 1920x1080(xxhdpi)的红米Note4X 真机|5.5吋 2560x1440(xxxhdpi)的谷歌PixelXL 真机
:–😐:–😐:–😐:–😐:–:
效果(压缩成 480p 的)|||||

存在的问题

文本内容显示不全或特别小是因为:文本字号使用的是默认的 14sp,不能和容器尺寸关联


AutoLayout

布局

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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?xml version="1.0" encoding="utf-8"?>
<com.zhy.autolayout.AutoRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg">

<com.zhy.autolayout.AutoRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="40px"
android:paddingRight="40px"
android:paddingTop="58px">

<ImageView
android:id="@+id/logo"
android:layout_width="194px"
android:layout_height="194px"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:src="@drawable/logo" />

<TextView
android:id="@+id/flatte"
android:layout_width="wrap_content"
android:layout_height="44px"
android:layout_below="@id/logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="40px"
android:includeFontPadding="false"
android:letterSpacing="1"
android:text="FLATTE"
android:textColor="#ffffff"
android:textSize="44px"
android:textStyle="bold" />

<TextView
android:id="@+id/socail_app"
android:layout_width="wrap_content"
android:layout_height="16px"
android:layout_below="@id/flatte"
android:layout_centerHorizontal="true"
android:layout_marginTop="40px"
android:includeFontPadding="false"
android:letterSpacing="0.1"
android:text="SOCAIL APP"
android:textColor="#fff048"
android:textSize="16px"
android:textStyle="bold" />

<com.zhy.autolayout.AutoRelativeLayout
android:id="@+id/container_user"
android:layout_width="match_parent"
android:layout_height="50px"
android:layout_below="@id/socail_app"
android:layout_marginTop="102px">


<com.zhy.autolayout.AutoRelativeLayout
android:id="@+id/user_icon"
android:layout_width="72px"
android:layout_height="match_parent">

<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="@drawable/user_icon" />
</com.zhy.autolayout.AutoRelativeLayout>

<com.zhy.autolayout.AutoRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/user_icon">


<TextView
android:id="@+id/form_user"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_alignParentBottom="true"
android:background="#8f9399" />

<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/form_user"
android:background="@null"
android:gravity="center_vertical"
android:hint="USERNAME OR EMAIL"
android:textColorHint="#ffffff"
android:textSize="18px" />
</com.zhy.autolayout.AutoRelativeLayout>
</com.zhy.autolayout.AutoRelativeLayout>

<com.zhy.autolayout.AutoRelativeLayout
android:id="@+id/container_password"
android:layout_width="match_parent"
android:layout_height="50px"
android:layout_below="@id/container_user"
android:layout_marginTop="40px">

<RelativeLayout
android:id="@+id/password_icon"
android:layout_width="72px"
android:layout_height="match_parent">

<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="@drawable/password_icon" />
</RelativeLayout>

<com.zhy.autolayout.AutoRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/password_icon">

<TextView
android:id="@+id/form_password"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_alignParentBottom="true"
android:background="#8f9399" />

<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/form_password"
android:background="@null"
android:gravity="center_vertical"
android:inputType="textPassword"
android:text="password"
android:textColorHint="#ffffff"
android:textSize="18px" />
</com.zhy.autolayout.AutoRelativeLayout>
</com.zhy.autolayout.AutoRelativeLayout>

<TextView
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="92px"
android:layout_below="@id/container_password"
android:layout_marginTop="40px"
android:background="@drawable/bg_login"
android:gravity="center"
android:text="LOGIN"
android:textColor="#434a54"
android:textSize="20px"
android:textStyle="bold" />

<TextView
android:id="@+id/forget_password"
android:layout_width="match_parent"
android:layout_height="16px"
android:layout_below="@id/login"
android:layout_marginTop="40px"
android:gravity="center"
android:includeFontPadding="false"
android:text="FORGET PASSWORD"
android:textColor="#fcfcfc"
android:textSize="16px"
android:textStyle="bold" />

<TextView
android:id="@+id/register"
android:layout_width="match_parent"
android:layout_height="92px"
android:layout_below="@id/forget_password"
android:layout_marginTop="40px"
android:background="@drawable/bg_register"
android:gravity="center"
android:text="REGISTER"
android:textColor="#ffee58"
android:textSize="20px"
android:textStyle="bold" />


<com.zhy.autolayout.AutoLinearLayout
android:id="@+id/container_login_with_third_part_center"
android:layout_width="match_parent"
android:layout_height="96px"
android:layout_below="@id/register"
android:layout_marginTop="40px">

<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/facebook" />

<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/twitter" />

<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/google" />
</com.zhy.autolayout.AutoLinearLayout>
</com.zhy.autolayout.AutoRelativeLayout>
</com.zhy.autolayout.AutoRelativeLayout>

效果

设备|9.6吋 1280x800(mdpi)的荣耀畅玩平板2 真机|4吋 800x480(hdpi)的谷歌NexusS 模拟器|5.65吋 1440x720(xhdpi)的荣耀9Lite 真机| 5.5吋 1920x1080(xxhdpi)的红米Note4X 真机|5.5吋 2560x1440(xxxhdpi)的谷歌PixelXL 真机
:–😐:–😐:–😐:–😐:–:
效果(压缩成 480p 的)|||||

存在的问题

1、当存在虚拟按键时,布局不随虚拟按键的隐藏/显示而动态改变
2、当虚拟按键是在设备 root 后强制隐藏的,此时获取的屏幕高度不正确


ConstraintLayout && AutoLayout

布局

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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<?xml version="1.0" encoding="utf-8"?>
<io.weichao.autolayout.widget.AutoConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg">

<View
android:id="@+id/view_top"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.051056338028169"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/view_left"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.0625" />

<View
android:id="@+id/view_right"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.0625" />

<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:adjustViewBounds="true"
android:src="@drawable/logo"
app:layout_constraintHeight_percent="0.1707746478873239"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_top" />

<View
android:id="@+id/view_2"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0352112676056338"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/logo" />

<TextView
android:id="@+id/flatte"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center"
android:includeFontPadding="false"
android:letterSpacing="1"
android:text="FLATTE"
android:textColor="#ffffff"
android:textSize="44px"
android:textStyle="bold"
app:layout_constraintHeight_percent="0.0387323943661972"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_2" />

<View
android:id="@+id/view_3"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0352112676056338"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/flatte" />

<TextView
android:id="@+id/socail_app"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center"
android:includeFontPadding="false"
android:letterSpacing="0.1"
android:text="SOCAIL APP"
android:textColor="#fff048"
android:textSize="16px"
android:textStyle="bold"
app:layout_constraintHeight_percent="0.0140845070422535"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_3" />

<View
android:id="@+id/view_4"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0889084507042254"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/socail_app" />

<io.weichao.autolayout.widget.AutoConstraintLayout
android:id="@+id/container_user"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0440140845070423"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_4">

<RelativeLayout
android:id="@+id/user_icon"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.1125">

<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="@drawable/user_icon" />
</RelativeLayout>

<io.weichao.autolayout.widget.AutoConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/user_icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/form_user"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="#8f9399"
android:includeFontPadding="false"
android:textSize="16px"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />

<EditText
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@null"
android:gravity="center_vertical"
android:hint="USERNAME OR EMAIL"
android:textColorHint="#ffffff"
android:textSize="16px"
app:layout_constraintBottom_toTopOf="@id/form_user"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</io.weichao.autolayout.widget.AutoConstraintLayout>
</io.weichao.autolayout.widget.AutoConstraintLayout>

<View
android:id="@+id/view_5"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0352112676056338"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/container_user" />

<io.weichao.autolayout.widget.AutoConstraintLayout
android:id="@+id/container_password"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0440140845070423"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_5">

<RelativeLayout
android:id="@+id/password_icon"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.1125">

<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="@drawable/password_icon" />
</RelativeLayout>

<io.weichao.autolayout.widget.AutoConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/password_icon"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/form_password"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="#8f9399"
android:includeFontPadding="false"
android:textSize="16px"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />

<EditText
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@null"
android:gravity="center_vertical"
android:inputType="textPassword"
android:text="password"
android:textColorHint="#ffffff"
android:textSize="16px"
app:layout_constraintBottom_toTopOf="@id/form_password"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</io.weichao.autolayout.widget.AutoConstraintLayout>
</io.weichao.autolayout.widget.AutoConstraintLayout>

<View
android:id="@+id/view_6"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0352112676056338"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/container_password" />

<io.weichao.autolayout.widget.AutoConstraintLayout
android:id="@+id/container_login"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/bg_login"
app:layout_constraintHeight_percent="0.0809859154929577"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_6">

<View
android:id="@+id/view_10"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.391304347826087"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/login"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center"
android:includeFontPadding="false"
android:text="LOGIN"
android:textColor="#434a54"
android:textSize="20px"
android:textStyle="bold"
app:layout_constraintHeight_percent="0.2173913043478261"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/view_10" />
</io.weichao.autolayout.widget.AutoConstraintLayout>

<View
android:id="@+id/view_7"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0352112676056338"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/container_login" />

<TextView
android:id="@+id/forget_password"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center"
android:includeFontPadding="false"
android:text="FORGET PASSWORD"
android:textColor="#fcfcfc"
android:textSize="16px"
android:textStyle="bold"
app:layout_constraintHeight_percent="0.0140845070422535"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_7" />

<View
android:id="@+id/view_8"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0352112676056338"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/forget_password" />

<io.weichao.autolayout.widget.AutoConstraintLayout
android:id="@+id/container_register"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/bg_register"
app:layout_constraintHeight_percent="0.0809859154929577"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_8">

<View
android:id="@+id/view_11"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.391304347826087"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/register"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center"
android:includeFontPadding="false"
android:text="REGISTER"
android:textColor="#ffee58"
android:textSize="20px"
android:textStyle="bold"
app:layout_constraintHeight_percent="0.2173913043478261"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/view_11" />
</io.weichao.autolayout.widget.AutoConstraintLayout>

<View
android:id="@+id/view_9"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0352112676056338"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/container_register" />

<LinearLayout
android:id="@+id/container_login_with_third_part_center"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.0845070422535211"
app:layout_constraintLeft_toRightOf="@id/view_left"
app:layout_constraintRight_toLeftOf="@id/view_right"
app:layout_constraintTop_toBottomOf="@id/view_9">

<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/facebook" />

<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/twitter" />

<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/google" />
</LinearLayout>
</io.weichao.autolayout.widget.AutoConstraintLayout>

效果

设备|9.6吋 1280x800(mdpi)的荣耀畅玩平板2 真机|4吋 800x480(hdpi)的谷歌NexusS 模拟器|5.65吋 1440x720(xhdpi)的荣耀9Lite 真机| 5.5吋 1920x1080(xxhdpi)的红米Note4X 真机|5.5吋 2560x1440(xxxhdpi)的谷歌PixelXL 真机
:–😐:–😐:–😐:–😐:–:
效果(压缩成 480p 的)|||||



百分比布局方案对比
https://weichao.io/ad8a3be0db54/
作者
魏超
发布于
2018年2月12日
更新于
2022年12月4日
许可协议