zoukankan      html  css  js  c++  java
  • 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+权*剩余空间

  • 相关阅读:
    山寨 《寻找房祖名》
    css3 弹性效果上下翻转demo
    CSS3 Hover 动画特效
    判断一个字符串通过变化字符的位置,是否可以组成回文
    获取多个字符串中的共同字符
    转换为回文的步数
    IOS中图片的一些处理方法
    python django的一点笔记
    一个图片切割的例子
    一个批量修改文件夹中文件名的命令
  • 原文地址:https://www.cnblogs.com/sunjianfei/p/5844865.html
Copyright © 2011-2022 走看看