layout_weight使用
layout_weight的真正含义是等比例分割剩余空间,
在线性布局(linearlayout)中对宽度和高度进行比例分割,
三个子linearlayout分割父linearlayout高度,代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.sunjianfei.linearlayout_test.MainActivity"
android:orientation="vertical"
android:id="@+id/linearall"> <LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=""
android:id="@+id/linear1"
android:background="#ff0000"
android:gravity="center_horizontal">
</LinearLayout> <LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=""
android:id="@+id/linear2"
android:background="#aa10ff"
> </LinearLayout> <LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=""
android:id="@+id/linear3"
android:background="#000000" >
</LinearLayout>
</LinearLayout>
三个linearlayout的比为1:2:3;
三个linearlayout的layout_height为"match_parent",那么剩余空间为1P-3P=-2P;
第一个linearlayout的高度:P+1/6*(-2P)=2/3P;
第二个linearlayout的高度:P+2/6*(-2P)=1/3P;
第三个linearlayout的高度:P+3/6*(-2P)=0;
所以三个linearlayout的实际高度比为2:1:0;
如果是两个linearlayout的比为1:2;
也是同样的计算,
剩余空间:P-2P=-P;
第一个linearlayout的高度:P+1/3*(-P)= 2/3P;
第二个linearlayout的高度:P+2/3*(-P)= 1/3P;
如果是四个五个平分也是同样的计算方法:
高度/宽度 = P+权*剩余空间
layout_weight使用的更多相关文章
- Android layout_weight理解
layout_weight属性只能用于LinearLayout布局,不能用于RelativeLayout等其他布局: layout_weight属性如果不设定,默认值为0: layout_weight ...
- Invalid layout param in a LinarLayout: layout_weight
android:layout_weight只适用于线性布局LinearLayout,不适用于相对布局RelativeLayout.
- 浅谈Android中layout_weight
引言 在开发android过程中,我们经常需要对界面进行按比例进行布局,我们一般都会使用layout_属性来进行设置.今天这篇文章我们就来简单介绍下layout_weight的使用和布局原理.随着做项 ...
- Android之layout_weight解析
我们先来看以下这段Android布局代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi ...
- 【Android学习】android:layout_weight的用法实例
对于android:layout_weight的用法,用下面的例子来说明: <LinearLayout xmlns:android="http://schemas.android.co ...
- android:layout_weight的真实含义(转)
首先声明只有在Linearlayout中,该属性才有效.之所以Android:layout_weight会引起争议,是因为在设置该属性的同时,设置android:layout_width为wrap_c ...
- Android:Layout_weight的深刻理解
最近写Demo,突然发现了Layout_weight这个属性,发现网上有很多关于这个属性的有意思的讨论,可是找了好多资料都没有找到一个能够说的清楚的,于是自己结合网上资料研究了一下,终于迎刃而解,写出 ...
- android layout_weight讲解
Layout_weight是线性布局,也就是LinearLayout里面用到的,下面通过实验来看这个Layout_weight的特性. 1.当控件的属性android:layout_width=&qu ...
- android中布局文件中 layout_weight 的属性详解
在不同的情况下,layout_weight属性作用是不同的.主要有两种属性: 1.当布局中的控件的尺寸(宽和高)都有指定时,它所表示的该控件在父容器中的比重,及它在父容器中所占的比例,数值越大,比重越 ...
- layout_weight详解
注:LinearLayout中的TextView按比例显示的时候,layout_width="0dp"或者layout_height="0dp" 在androi ...
随机推荐
- JAVA 定时器时间格式
格式: [秒] [分] [小时] [日] [月] [周] [年] 通配符说明: \*:表示所有值.例如:在分的字段上设置"\*",表示每一分钟都会触发. ?:表示不指定值.使用的场 ...
- 学习 swift (1)
https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwi ...
- zoj4016 Mergeable Stack
题意:对n个栈,有q次操作.每个操作可能为三种情况中的一种:1.将v插入到s栈的顶端:2.输出s栈的栈顶(若栈为空则输出empty):3.将栈t插入到栈s的栈顶. 开始考虑到指针可能会mle,用数组模 ...
- (2)Oracle基础--表空间
· 表空间概述 <1> 理解表空间 ① 表空间与数据库的关系: 表空间是数据库的逻辑存储空间,可以理解为在数据库中开辟的一块空间,用于存放数据库的对象. 一个数据库可以由多个表空间构成.O ...
- VSCode保存插件配置并使用 gist 管理代码片段
setting sync 保存配置 由于公司和家里都使用 VSCode 作为主要编辑器,同步配置是最紧要的.VSCode 提供了setting sync插件,很方便我们同步插件配置.引用网上教程: 在 ...
- ReentrantLock总体概括
一.锁的实现原理: JAVA concurrent包下面的锁是通过AbstractQueuedSynchronizer内的Node类下面的state属性来实现的,并且锁的可重入属性也是通过state实 ...
- 4. Neural Network
1. 神经网络 首先引入一些便于稍后讨论的新标记: $L$:代表神经网络层数$S_l$:代表第$l$层处理单元的个数$K$:代表多分类中类别种数 2. 前向传播(forward propagation ...
- WebDriverAPI(3)
获取页面的Title属性 被测网址http:http://www.baidu.com Java语言版本的API实例代码 String url = "http://www.baidu.com& ...
- Java Web入门学习(四)Eclipse与Maven、Tomcat整合配置 (重整版并解决问题)
Java Web学习(四)Eclipse与Maven整合配置 (重整版) 一.准备工作 1.Tomcat 8.5.15 2.Maven3.5 3.Eclipse Neon.3 Release (4.6 ...
- http正向代理与反向代理
转自:https://baijiahao.baidu.com/s?id=1566988836622068&wfr=spider&for=pc 一句话总结正向代理与反向代理的区别:正向代 ...