LinearLayout内的权重属性 weight
2016-05-04 23:37
344 查看
1、首先设置是横向还是纵向,如果是横向,设置横向width 都是0dp ,weight就是对应的权重,比如,两个按钮 权重分别是1,2,那么第一个按钮占得距离是1/3,第二个是2/3
2、如果对应的宽度或者高度是match,那么计算权重时需要首先计算出总长度或者总高度, 公式= 原宽度+剩余宽度的百分比
例如: 两个横向的按钮 宽度都是 match_parent ,权重分别是1,2 那么第一个按钮的距离=L+(L-2L)*(1/3)= 2/3L
3、如果三个控件使用权重,
2、如果对应的宽度或者高度是match,那么计算权重时需要首先计算出总长度或者总高度, 公式= 原宽度+剩余宽度的百分比
例如: 两个横向的按钮 宽度都是 match_parent ,权重分别是1,2 那么第一个按钮的距离=L+(L-2L)*(1/3)= 2/3L
3、如果三个控件使用权重,
android:baselineAligned="false"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:baselineAligned="false" android:orientation="horizontal"> <TextView android:background="#ff0000" android:gravity="center" android:layout_width="0dp" android:layout_height="45dp" android:layout_weight="1" android:text="abdcde/ncdd"/> <TextView android:background="#0f0" android:gravity="center" android:layout_width="0dp" android:layout_height="45dp" android:layout_weight="2" android:text="第二个"/> <TextView android:background="#00f" android:gravity="center" android:layout_width="0dp" android:layout_height="45dp" android:layout_weight="3" android:text="第三个"/> </LinearLayout>
相关文章推荐
- Mac OS下PHP开发环境的搭建——基于XAMPP和IntelliJ IDEA
- Linux小记(一):Supervisor利器
- VIM复制和粘贴
- JSP 9对象
- 往服务器发送自定义的对象
- android-Ultra-Pull-To-Refresh/SwipeRefreshLayout嵌套ViewPager/ScrollView滑动冲突解决
- AngularJs & JQuery 结合使用存在的问题 之 input hidden 问题解决方案
- 对于每个小组的意见
- 边双连通 练习
- 回文链表之程序员面试经典
- [Java] 作业5 (数组)
- 系统定制封装 step1
- img标签详解
- Uva 657 The die is cast
- iOS宏一些使用
- WEB开发的套路——WEB工程的套路
- java 正则表达式去除标点符号
- Swift 仿简书、淘宝App的弹出view效果
- AngularJs学习笔记--Scope
- html的笔记