• 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="1"
            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="2"
            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="3"
            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+权*剩余空间

  • 相关阅读:
    远程服务器上的weblogic项目管理(二)发布完成后如何重启weblogic容器
    Oracle中日期和时间类函数
    程序员应如何提高实效?读《程序员修炼之道》有感
    远程服务器上的weblogic项目管理(一)项目部署与更新流程
    远程服务器上的weblogic项目管理(四)filelock not found错误解决方法
    浅拷贝与深拷贝
    for...of 与 for...in
    工厂函数创建对象
    Promise
    闭包内存泄漏解决方法
  • 原文地址:https://www.cnblogs.com/sunjianfei/p/5844865.html
Copyright © 2020-2023  润新知