LinearLayout中的layout_weight属性详解
来源:互联网 发布:怎样在淘宝上买弩 编辑:程序博客网 时间:2024/05/16 23:34
线性布局中的layout_weight顾名思义即为定义各个组件在整个界面中所占的权重。常用两种实现方法
1:最为简单的实现方法,当orientation为水平时垂直layout_height=''0dp",同理当orientation为垂直时,将layout_width设定为0dp,此时在一个直接父布局中layout_width中的数值越大这个组件占的界面就越大。示例代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <LinearLayout android:layout_width="0dp" android:layout_height="fill_parent" android:background="#ADFF2F" android:layout_weight="1"/> <LinearLayout android:layout_width="0dp" android:layout_height="fill_parent" android:background="#DA70D6" android:layout_weight="2"/> </LinearLayout>
运行图:
下面来讨论另外一种情况,当水平按照权重分割屏幕时,此时将layout_width设置为wrap_content,此时layout_weight的数值仍遵循数值越大占的屏幕越大。
那么假如layout_width设置为fill_parent呢?
这里介绍一种计算方法,这里预先设置一个变量暂时定义为queshao(缺少),例如在一个orientation为horizontal的LinearLayout中,有三个组件的layout_width都设定为了fill_parent,此时queshao=1-3 = -2(因为只有一个parent大家都想fill_parent,那么此时就缺少一个parent)
假如这三个组件的layout_weight依次为1 2 3,那么公式如下:
第一个组件:1-queshao*(1/(1+2+3))=2/3
第二个组件:1-queshao*(2/(1+2+3)) = 1/3
第三个组件:没空了~~
示例代码及运行图:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="one" android:background="#98FB98" /> <TextView android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="two" android:background="#FFFF00" /> <TextView android:layout_weight="3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="three" android:background="#FF00FF" /> </LinearLayout>
未完待续。。。
0 0
- LinearLayout中的layout_weight属性详解
- LinearLayout中的layout_weight属性
- LinearLayout中的layout_weight属性
- LinearLayout中的layout_weight属性
- LinearLayout中的layout_weight属性
- LinearLayout中的layout_weight属性
- LinearLayout中的layout_weight属性
- LinearLayout中的layout_weight属性 的使用
- LinearLayout中的layout_weight属性深入研究
- LinearLayout中layout_weight属性
- LinearLayout中layout_weight属性
- LinearLayout的layout_weight属性
- Android中的layout_weight属性详解
- LinearLayout的andrid:layout_weight属性的使用详解
- LinearLayout的andrid:layout_weight属性的使用详解
- 日积月累:LinearLayout的andrid:layout_weight属性的使用详解
- LinearLayout的andrid:layout_weight属性的使用详解
- LinearLayout中的android:layout_weight属性的设置和使用
- Quora的技术探索
- JAVA多线程实现方式主要有三种:继承Thread类、实现Runnable接口、使用ExecutorService、Callable、Future实现有返回结果的多线程。其中前两种方式线程执行完后都没
- 【转载】Ubuntu12.04/14.04无线信号不稳的解决办法
- C语言之坑二--定义不定长数组
- POJ 3258 River Hopscotch (二分)
- LinearLayout中的layout_weight属性详解
- linux命令笔记(二)
- unity自带寻路Navmesh入门教程(二)
- HDU2099 整除的尾数【水题】
- 发明专利跃上国民经济成绩单
- unity之NGUI3
- C封装的Socket,激活GPRS来获取网络访问权限
- BZOJ 1090 SCOI2003 字符串折叠 动态规划+Hash
- hdu 5113 Black And White (dfs回溯+剪枝)