Android学习笔记----layout_weight属性解析
来源:互联网 发布:9.9元天天特价淘宝童装 编辑:程序博客网 时间:2024/04/29 02:59
android:layout_weight属性只有在Linearlayout中起作用,而且分别设置android:layout_width为wrap_content和match_parent会造成两种截然相反的效果。
<span style="font-family:SimSun;"><LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="@color/black" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="2" android:background="@color/green" /></LinearLayout></span>
两个TextView的宽度均设为match_parent,一个权重为1,一个权重为2.得到效果如下:
权重为1的反而占了三分之二!
更改布局如下
<strong><LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="0" <!-- 为了让宽度的比例为严格的 1:2 此处需将宽度设置为0 当然如果不是很严格的话可以是wrap_content--> android:layout_height="wrap_content" android:layout_weight="1" android:background="@color/black" /> <TextView android:layout_width="0" <!-- 为了让宽度的比例为严格的 1:2 此处需将宽度值设置为0 当然如果不是很严格的话可以是wrap_content --> android:layout_height="wrap_content" android:layout_weight="2" android:background="@color/green" /> </LinearLayout> </strong>也就是把宽度修改为wrap_content,此时会看到如下的效果
左边 TextView占比三分之一,又正常了。
android:layout_weight的真实含义是:一旦View设置了该属性(假设有效的情况下),那么该 View的宽度等于原有宽度(android:layout_width)加上剩余空间的占比!
设屏幕宽度为L,在两个view的宽度都为match_parent的情况下,原有宽度为L,两个的View的宽度都为L,那么剩余宽度为L-(L+L) = -L, 左边的View占比三分之一,所以总宽度是L+(-L)*1/3 = (2/3)L.
0 0
- Android学习笔记----layout_weight属性解析
- Android-Layout_weight属性解析(慕课网笔记)
- Android:Layout_weight属性解析
- android:layout_weight属性学习
- Android 笔记 linearlayout 属性 layout_weight
- Android布局之Layout_weight属性解析
- 属性“layout_weight”解析
- Layout_weight属性解析
- layout_weight属性解析
- 布局属性layout_weight解析
- android---android:layout_weight属性
- Android学习笔记(四)layout_weight
- Android学习笔记(二):layout_weight的解读
- android layout_weight 属性
- android:layout_weight属性详解
- Android layout_weight属性
- android:layout_weight属性详解
- android:layout_weight属性探讨
- 找回Python IDLE Shell里的历史命令(用上下键翻历史命令怎么不好用了呢?)
- linux运维路线
- iOS之 TCP socket网络编程 demo
- [数位DP] hihoCoder#1033 交错和
- Android系统镜像改造指南
- Android学习笔记----layout_weight属性解析
- MT模式下静态链接错误的问题
- 高精度 加 减 乘
- linux小学生(一)之 linux简介
- java中的转义字符
- 进程组ID
- mysql explain 执行计划解读
- STM32F407学习记录1:MDK开发环境一些配置
- android使用隐藏api的方法(使用被@hide的api)