zoukankan      html  css  js  c++  java
  • 四十四、Android之android:layout_weight详解

    1、LinearLayout可以为其包含控件指定填充权值layout_weight。 这样就允许其包含的控件可以填充屏幕上的剩余空间。这也避免了所有控件挤成一堆的情况,而是允许他们放大填充所有空白。剩余的空间会按这些控件指定的权值比例分配屏幕。

                   
    2、默认情况下,weight的值是0,表示按照控件的实际大小显示;如果weight设置高于零。

                    
    3、剩余空间会按照该控件的weight值占所有控件weight的比例分配给该控件。 比如有两个控件,一个weight为1,另外一个是2. 则剩余空间会把1/(1+2)的部分给控件一,另外2/(1+2)的分配给控件二。也就是权值越大,重要度越大。

                     
    4、如果LinearLayout包含子LinearLayout,子LinearLayout之间的权值越大的,重要度则越小。如果有LinearLayout A包含LinearLayout C,D,C的权值为2,D的权值为1,则屏幕的2/3空间分给权值为1的D,1/3分给权值为2的C。在LinearLayout嵌套的情况下,子LinearLayout必须要设置权值,否则默认的情况是未设置权值的子LinearLayout占据整个屏幕。

                  

               

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" 
            android:layout_weight="2">
    	    <SurfaceView
    	        android:id="@+id/surfaceView"
    	        android:layout_width="fill_parent"
    	        android:layout_height="fill_parent" />
        </LinearLayout>
        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" 
            android:layout_weight="1"
            android:layout_gravity="center">
            <Button android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/btnTakePicture"
                android:gravity="center"
                android:textSize="20px"
                android:text="拍照"/>
        </LinearLayout>
    
    </LinearLayout>
    
  • 相关阅读:
    Haproxy+Keepalived高可用环境部署梳理(主主和主从模式)
    使用nginx sticky实现基于cookie的负载均衡
    CENTOS 6.6初始化SHELL脚本
    Java 开源博客 Solo 1.2.0 发布
    Java 开源博客 Solo 1.2.0 发布
    Java多线程-synchronized关键字
    Maven项目pom.xml配置详解
    4.0 苹果系统安装之黑苹果(4)
    3.0 Windows和Linux双系统安装(3)
    2.0 Linux系统的安装之Fedora安装单系统(2)
  • 原文地址:https://www.cnblogs.com/linjiqin/p/2303519.html
Copyright © 2011-2022 走看看