layout_width与layout_weight
来源:互联网 发布:小众软件网 编辑:程序博客网 时间:2024/05/16 05:27
同时设置layout_width与layout_weight:,layout_width为0dp时 layout_weight生效 当layout_width不为0时 优先生效 其次layout_weight
1, 当layout_width为0dp时
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:orientation="horizontal" android:layout_weight="1" android:layout_height="0dp" > <TextView android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:background="#98FB98" /><TextView android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:background="#FFFF00" /><TextView android:layout_width="0dp" android:layout_weight="3" android:layout_height="match_parent" android:background="#FF00FF" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="20dp" android:background="#fff" > </LinearLayout> <LinearLayout android:layout_width="match_parent" android:orientation="horizontal" android:layout_weight="1" android:layout_height="0dp" > <TextView android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:background="#98FB98" /><TextView android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:background="#FFFF00" /><TextView android:layout_width="0dp" android:layout_weight="3" android:layout_height="match_parent" android:background="#FF00FF" /> </LinearLayout> </LinearLayout>
2;将左上的textview 的layout_width="wrag_content" 与上图一样 但是 向里面添加text""就会不一样了:
<TextView android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="match_parent" android:background="#98FB98" android:text="aaaaaaaaaaaaaaaaaaaaaa" />
wrap_content先起作用根据内容占据相应的空间 最后再按照weight分
3.将 layout_width设置成match_parent 会发现第三个textview不见了
屏幕只有一个宽设为x 但是a,b,c都想占满 . a直接占住屏幕 b,c在占时屏幕没了 这个时候缺少2个屏幕了 也就是-2 每个view权重仍然会去分
a的实际宽度应该为 width+剩下屏幕*(weightA)/(weightA+weightB+weightC) 也就是 x+(-2x)*(weightA)/(weightA+weightB+weightC) 3/5x
b同理x+(-2x)*(weightA)/(weightA+weightB+weightC) 3/5x 此时 a ,b合起来一起超过x了 所以b为2/5x c无立足之地 就这样消失了..
总结: 每个组件的layout_width属性先占去一部分 剩下的weight分
每个组件的实际宽度为 layout_width +剩下的根据weight分来的(剩下的指的是 屏幕的总宽-每个组件的width)
设 总宽 为 x 有三个组件每个的 width为 xa xb xc weight为 wa wb wc
a的实际宽 xa+(x-xa-xb-xc)*(wa/(wa+wb+wc))
b c也是一样的计算方法
- layout_width与layout_weight
- Android布局中Layout_weight与layout_width、orientation
- Android layout_width和layout_weight关系
- layout_width和layout_weight的区别
- 关于Android UI组件LinearLayout属性layout_weight与layout_width/height的问题
- 关于Android UI组件LinearLayout属性layout_weight与layout_width/height的问题
- layout_weight和layout_width/layout_height的结合
- android:layout_width="wrap_content"让android:layout_weight="1"无效
- Android layout_width和layout_weight组合之后呈现的视图
- Android layout_weight layout_width ,Listview单行特定textview省略
- android:layout_width="0dp", android:layout_weight="1"
- 关于android:layout_weight= android:layout_width android:layout_height android:gravity的问题
- LinearLayout布局中Layout_weight的深刻理解-为何需设置android:layout_width="0dp"
- LinearLayout布局中Layout_weight的深刻理解-为何需设置android:layout_width="0dp"
- 官网:layout_weight="1",layout_width="0dp"可提高性能
- android:layout_width与android:with的区别
- android:layout_width与android:width的区别
- android:layout_height与android:layout_width属性解析
- Struts2 学习系列 (6) 消息处理与国际化
- C++之string学习笔记(1)
- Android-Universal-Image-Loader图片加载框架使用
- ubuntu sublime中文输入
- Android系统手机端抓包方法
- layout_width与layout_weight
- c语言之指针数组理解三
- c++中string类的详解
- poj1328
- Testing Round #12
- 1936 哪一瓶是毒药?
- Spring 4支持的Java 8新特性一览
- Android网络优化2--HttpClinet
- servlet使用json案例,提供jar文件下载