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 ...
随机推荐
- Linux快速学习系列
这篇文章会随着学习的进行,不断的更新!!! 总结 操作系统引入的抽象概念 进程(process) 地址空间(address space) 虚拟内存(virtual memory) 操作系统引入的cah ...
- 伸展树的实现——c++
一.介绍 伸展树(Splay Tree)是一种二叉排序树,它能在O(log n)内完成插入.查找和删除操作.它由Daniel Sleator和Robert Tarjan创造.(01) 伸展树属于二叉 ...
- java中关键字static和final
面向对象的不足 凡是有利必有弊,强对象编程,使得语法简单统一,但也有其缺点,而且有很多.我们在接下来的课程里会一点点接触到.我们今天先看第一个. 有些变量和函数确实没必要定义在一个类里.强行规定这些函 ...
- Get Requests with Json Data && Get Requests with Url Parameters
- Django中指定生成表名的方法
在模型类中定义元类: class Meta: de_table = 'tableName' #指定表名
- python3模块: uuid
一. 简介 UUID是128位的全局唯一标识符,通常由32字节的字母串表示.它可以保证时间和空间的唯一性,也称为GUID. 全称为:UUID--Universally Unique IDentifie ...
- 【洛谷p3994】Highway 二分+斜率优化DP
题目大意:给你一颗$n$个点的有根树,相邻两个点之间有距离,我们可以从$x$乘车到$x$的祖先,费用为$dis\times P[x]+Q[x]$,问你除根以外每个点到根的最小花费. 数据范围:$n≤1 ...
- jmeter -- 在beanshell中拿到请求body参数和header参数
beanshell: import org.apache.jmeter.config.Arguments; import org.apache.jmeter.protocol.http.control ...
- 漫谈NIO(1)之计算机IO实现
1.前言 此系列将尽可能详细介绍断更博客半年以来个人的一个成长,主要是对Netty的源码的一个解读记录,将从整个计算机宏观IO体系上,到Java的原生NIO例子最后到Netty的源码解读.不求完全掌握 ...
- xampp启动失败 Apache shutdown unexpectedly
我知道是端口被我的虚拟机占用,但是我的虚拟机也要同时打开,所以 我需要修改xampp的端口 1, 2修改二个配置文件 修改httpd.conf 修改httpd-ssl.conf 4,重启xampp