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. TensorFlow从1到2(十)带注意力机制的神经网络机器翻译

    基本概念 机器翻译和语音识别是最早开展的两项人工智能研究.今天也取得了最显著的商业成果. 早先的机器翻译实际脱胎于电子词典,能力更擅长于词或者短语的翻译.那时候的翻译通常会将一句话打断为一系列的片段, ...

  2. AJPFX的监管与执照

      AJPFX受到英国金融行为监管局(FCA)授权和监管. 英国FCA是目前世界上金融服务最完善.最健全的监管机构,英国FCA对所有在其境内注册的金融服务机构进行严格的监管. 英国金融行为监管局(FC ...

  3. day 113 爬虫框架

    基础配置

  4. fedora 国内源

    wget http://mirrors.163.com/.help/fedora-163.repowget http://mirrors.163.com/.help/fedora-updates-16 ...

  5. LOJ#3088. 「GXOI / GZOI2019」旧词(树剖+线段树)

    题面 传送门 题解 先考虑\(k=1\)的情况,我们可以离线处理,从小到大对于每一个\(i\),令\(1\)到\(i\)的路径上每个节点权值增加\(1\),然后对于所有\(x=i\)的询问查一下\(y ...

  6. jzoj5894

    先前綴和一發,問題表示求[0-l2][0-r2]滿足條件的數的個數 假設可以把某一個數拆分成[前面任意個數][00-0-11-1(個數相同)]的區間 那麼問題會簡單的多,因為任意一個a位的整數分別xo ...

  7. 使用python进行短信轰炸

    本文作者:i春秋作家——Hacker1ee 大家好,我是1ee(因为在作家群,就不加Hacker这个前缀了,怕被大佬打..) 刚加入i春秋作家组希望大家多多关照,也欢迎大家找我交流 今天我来讲讲我最近 ...

  8. jvm内存结构(一)(结构总览)

    jvm内存结构:<Java虚拟机原理图解>3.JVM运行时数据区 程序计数器: ,是执行的字节码的行号指示器,记录的是正在执行的虚拟机字节码指令的地址. ,每个线程都有独立计数器,互不干扰 ...

  9. 下载Centos7 64位镜像

    下载Centos7 64位镜像 1.打开Centos官网 打开Centos官方网站地址:https://www.centos.org/,点击Get CentOS Now 2.点击Minimal ISO ...

  10. document文档对象

    document 文挡对象 - JavaScript脚本语言描述———————————————————————注:页面上元素name属性和JavaScript引用的名称必须一致包括大小写否则会提示你一 ...