zoukankan      html  css  js  c++  java
  • layout_weight 属性分析

    以如下布局为例:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <LinearLayout android:orientation="horizontal"
            android:layout_width="fill_parent" android:layout_height="wrap_content">
            <Button android:layout_width="fill_parent" android:text="@string/bt_show1"
            android:textColor="#ff0000"
                android:layout_height="wrap_content" android:layout_weight="10.0" />
    
            <Button android:layout_width="fill_parent" android:text="@string/bt_show2"
            android:textColor="#ff0000"
                android:layout_height="wrap_content" android:layout_weight="1.0" />
    
        </LinearLayout>
    
    
        <LinearLayout android:orientation="horizontal"
            android:layout_width="fill_parent" android:layout_height="wrap_content">
            <Button android:layout_width="wrap_content" android:text="@string/bt_show3"
            android:textColor="#ff0000"
                android:layout_height="wrap_content" android:layout_weight="10.0" />
    
            <Button android:layout_width="wrap_content" android:text="@string/bt_show4"
            android:textColor="#ff0000"
                android:layout_height="wrap_content" android:layout_weight="1.0" />
    
        </LinearLayout>
    
    </LinearLayout>

    可以看作:

    1、全为wrap_content 时 layout_weight月接近0,越接近wrap_content(占比例越小)

          当layout_weight=0 时 ,width 为 wrap_content; 如果全部layout_weight =0 ,全部为wrap_content,而并不会和全为其他非零值时一样平均分割;

    2、全为fill_parent 时layout_weight越接近0,越接近fill_parent(占比例越大)

         有多个layout_weight为0时,第一个为0的充满父控件

    3、layout_weight 为负数则不在视图内

  • 相关阅读:
    拒绝喝酒理由1
    动态调用事件,事件的方法
    c#发送图片
    c#截屏功能的实现
    devexpress中文讨论论坛
    解析javascript变量
    devexpress_PivotGrid说明
    python学习之老男孩python全栈第九期_day022知识点总结——初识面向对象
    python学习之老男孩python全栈第九期_day022作业
    员工信息表
  • 原文地址:https://www.cnblogs.com/lipeil/p/2666883.html
Copyright © 2011-2022 走看看