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使用的更多相关文章

  1. Android layout_weight理解

    layout_weight属性只能用于LinearLayout布局,不能用于RelativeLayout等其他布局: layout_weight属性如果不设定,默认值为0: layout_weight ...

  2. Invalid layout param in a LinarLayout: layout_weight

    android:layout_weight只适用于线性布局LinearLayout,不适用于相对布局RelativeLayout.

  3. 浅谈Android中layout_weight

    引言 在开发android过程中,我们经常需要对界面进行按比例进行布局,我们一般都会使用layout_属性来进行设置.今天这篇文章我们就来简单介绍下layout_weight的使用和布局原理.随着做项 ...

  4. Android之layout_weight解析

    我们先来看以下这段Android布局代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi ...

  5. 【Android学习】android:layout_weight的用法实例

    对于android:layout_weight的用法,用下面的例子来说明: <LinearLayout xmlns:android="http://schemas.android.co ...

  6. android:layout_weight的真实含义(转)

    首先声明只有在Linearlayout中,该属性才有效.之所以Android:layout_weight会引起争议,是因为在设置该属性的同时,设置android:layout_width为wrap_c ...

  7. Android:Layout_weight的深刻理解

    最近写Demo,突然发现了Layout_weight这个属性,发现网上有很多关于这个属性的有意思的讨论,可是找了好多资料都没有找到一个能够说的清楚的,于是自己结合网上资料研究了一下,终于迎刃而解,写出 ...

  8. android layout_weight讲解

    Layout_weight是线性布局,也就是LinearLayout里面用到的,下面通过实验来看这个Layout_weight的特性. 1.当控件的属性android:layout_width=&qu ...

  9. android中布局文件中 layout_weight 的属性详解

    在不同的情况下,layout_weight属性作用是不同的.主要有两种属性: 1.当布局中的控件的尺寸(宽和高)都有指定时,它所表示的该控件在父容器中的比重,及它在父容器中所占的比例,数值越大,比重越 ...

  10. layout_weight详解

    注:LinearLayout中的TextView按比例显示的时候,layout_width="0dp"或者layout_height="0dp" 在androi ...

随机推荐

  1. VSCode开发(一)——入门基础

    8天掌握EF的Code First开发之Entity Framework介绍   返回<8天掌握EF的Code First开发>总目录 本篇目录 Entity Framework概要 什么 ...

  2. 1047 行 MySQL 详细学习笔记

    https://blog.csdn.net/baidu_25310663/article/details/86517610 Windows服务   -- 启动MySQL   net start mys ...

  3. Golang channel 的基本使用方法

    package main import ( "fmt" "learner/Add" "time" ) //a. 普通类型,普通变量保存的就是 ...

  4. Map-560. Subarray Sum Equals K

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  5. 2018 Multi-University Training Contest 4

    累惹. B. Harvest of Apples 题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6333 题意:求∑(i=0,m) C(n,m). 分 ...

  6. 【wireshark】插件开发(四):Lua插件Post-dissector和Listener

    1. Post-dissector post-dissector和dissector不同,它会在所有dissectors都执行过后再被执行,这也就post前缀的由来.post-dissector的构建 ...

  7. 在vue-cli建的vue项目中使用sass

    前面已使用vue-cli新建了一个vue项目,参考  使用命令行创建一个vue项目的全部命令及结果 首先看下新建项目的页面和代码,有部分修改,可忽视,如下图:     然后我们在页面添加sass的代码 ...

  8. Python “ValueError: incomplete format” print(“a%” % ”)

    解决python打印%号和%format输出问题 >>> print('%s' %'1') 1 >>> print('%s%' %'1') Traceback (m ...

  9. Lingo 做线性规划 - Financial Applications

    Reference: <An Introduction to Management Science Quantitative Approaches to Decision Making, Rev ...

  10. 手风琴图片和钢琴导航栏JQ滑动特效

    手风琴JQ滑动特效 1.效果预览: 2.相关代码: <!DOCTYPE html> <html lang="en"> <head> <me ...