Android 中weight使用的逻辑

来源:互联网 发布:智能网络电视排行榜 编辑:程序博客网 时间:2024/05/18 02:56
Weight

计算出的宽度= 原来宽度+剩余空间所占百分比的宽度

线性布局 水平排列 button1 和 button2
设屏幕宽度为 L

当宽度都设置为match_parent, button1的weight为1,button2的weight为2
Button1
2/3L = L +(L-2L)*1/3 = L-1/3L= 2/3L
Button2
1/3L = L +(L-2L)  *2/3 = L-2/3L= 1/3L


当宽度都设置为0dp, button1的weight为1,button2的weight为2

Button1

1/3L = 0 +L*1/3 = 1/3L

Button2

2/3L = 0 +L*2/3 = 2/3L






0 0
原创粉丝点击