我是靠谱客的博主 等待金针菇,这篇文章主要介绍Android 两个按钮平均占宽度示例,现在分享给大家,希望可以做个参考。

巧用gravity,padding, layout_weight和隔离墙

这个隔离墙是我自创的说法,这是个TextView,专门用来隔离和平均分布控件的。

隔离墙
复制代码
1
2
3
4
5
6
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" />
主布局
复制代码
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
<?xml version="1.0" encoding="utf-8"?> <com.zhy.autolayout.AutoLinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:padding="10px" android:layout_weight="1" android:gravity="center" android:layout_width="match_parent" android:layout_height="wrap_content"> <!--隔离墙--> <include layout="@layout/average_weight"/> <!-- 立即支付--> <com.zhy.autolayout.AutoLinearLayout android:layout_weight="1" android:gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:text="立即支付" android:textColor="@color/material_white" android:background="@drawable/activity_stock_market_warning_background" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </com.zhy.autolayout.AutoLinearLayout> <!--隔离墙--> <include layout="@layout/average_weight"/> <!-- 支付完成--> <com.zhy.autolayout.AutoLinearLayout android:layout_weight="1" android:gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:text="支付完成" android:textColor="@color/material_white" android:background="@drawable/fragment_order_wchat_button_completed_pay_background" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </com.zhy.autolayout.AutoLinearLayout> <!--隔离墙--> <include layout="@layout/average_weight"/> </com.zhy.autolayout.AutoLinearLayout>
效果图

在这里插入图片描述

最后

以上就是等待金针菇最近收集整理的关于Android 两个按钮平均占宽度示例的全部内容,更多相关Android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部