关于android LinearLayout 的layout_weight
来源:互联网 发布:手机excel软件下载 编辑:程序博客网 时间:2024/05/20 21:42
今天仔细看了一下layout_weight这个属性,发现它还真挺特别的,做以记录:
首先影响这个属性的因素主要和子控件的android:layout_width有关,也就是说当子控件的width是wrap_content时weight的值越大,这个子控件占的空间也就越大。
这时是成正比的关系 。
当子控件的android:layout_width是fill_parent时,就完全相反了,weight值越大,子控件占用的空间反而越小。
可以总结为 当填充属性是wrap_content时,随着layout_weight的变大,该控件的优先级越高,
当填充属性是fill_parent时,随着layout_wight的变大,该控件的优先级越低,两者正好相反
下面是布局
<?xml version="1.0"encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="red"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="green"
android:gravity="center_horizontal"
android:background="#00aa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="blue"
android:gravity="center_horizontal"
android:background="#0000aa"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="yellow"
android:gravity="center_horizontal"
android:background="#aaaa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="row one"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row two"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row three"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row four"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
效果如下四个颜色不一样大小是因为textview字数不同 把TextView中的属性android:layout_width值改为"fill_parent"就可以一样大小了。其他的效果自己试试就知道了。
LinearLayout之间的layout_weight设置带来的影响,将第一个LinearLayout的layout_weight设置为2之后 会发现它的布局变小了。也就是说weight越大占的比例反而越小。
也就是说LinearLayout之间的layout_weight是按照反比例分配空间的。
原帖地址:http://blog.csdn.net/myshapozi/article/details/8481991
- 关于android LinearLayout 的layout_weight
- LinearLayout的android:layout_weight
- 关于linearLayout的中 android:layout_weight 的使用
- LinearLayout的android:layout_weight的真实含义
- LinearLayout中android:layout_weight的作用
- LinearLayout中android:layout_weight的作用
- LinearLayout中android:layout_weight的作用
- Android 布局 LinearLayout 的 layout_weight 属性
- Android LinearLayout layout_weight的几点解释
- Android LinearLayout布局的layout_weight属性探究
- Android LinearLayout layout_weight
- 关于Android UI组件LinearLayout属性layout_weight与layout_width/height的问题
- 关于Android UI组件LinearLayout属性layout_weight与layout_width/height的问题
- 关于Android的layout_weight
- LinearLayout布局的Layout_weight
- LinearLayout布局的Layout_weight
- LinearLayout的layout_weight属性
- LinearLayout的layout_weight
- 事情时要考虑寻找一位Netflix的英国代理
- windows 如何查看端口占用情况
- Cached VS Buffers
- 买Hidemyass VPN
- 我的博客第一天
- 关于android LinearLayout 的layout_weight
- 新手学习C++笔记1:调试错误之找不到标识符
- VMware无法使用64位操作系统
- 第一篇
- 个人笔记(Oracle)—02
- 欧拉回路及欧拉路的判断
- 线性表 顺序存储 链式存储 ---java实现
- scalable high performance main memory system Using PCM Technology
- hd 2021 发工资咯:)