• [转]Android 中fill_parent与wrap_content的区别


     

       
    在Android中,对于组件的属性“layout_width”和“layout_height”,
    其值总是设置为“wrap_content”或“fill_parent”。
    那么,这两个值有什么不同呢?  请看下面的定义:  
    1. wrap_content:组件的大小以能装入其内容即可; 
     2. fill_parent:组件会显示得和其父组件一样大,并填充剩余的空间(在 API Level 8中命名为 match_parent)。
     
    eg:
    1.设置为warp_parent
     
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />
       
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="FINISH"/>
    放置一个Button组件,并设置其宽度和高度为wrap_parent,这会告诉Android将按钮显示为能够装下其内容。
    Android <wbr>中fill_parent与wrap_content的区别

    2.设置宽为fill_parent
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />
       
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="FINISH"/>
    将layout_width的值改为fill_parent,现在按钮的宽度填充了剩余的空间,与其父组件Textview的宽度一样,单高度依然是保持在紧紧能容纳下内容。
    Android <wbr>中fill_parent与wrap_content的区别
    3.设置高度为fill_parent
     
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />
       
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="FINISH"/>
    将layout_width的值改为fill_parent,现在按钮的宽度填充了剩余的空间,与其父组件Textview的宽度一样,单高度依然是保持在紧紧能容纳下内容。
    Android <wbr>中fill_parent与wrap_content的区别
    4.设置为fill_parent
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />
       
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="FINISH"/>
    设置其宽度和高度为wrap_parent,这会告诉Android将按钮显示为与整个屏幕一样大,它将填充整个屏幕空间
    Android <wbr>中fill_parent与wrap_content的区别
    实际上,我们可以指定确切的宽度和高度,不过不建议这样做,因为Android有多种设备屏幕尺寸。我们不知道我们的应用程序会跑在哪一种尺寸的Android设备上。。。。
  • 相关阅读:
    黑马程序员——JAVA基础之System,Runtime,Date,Calendar,Math
    黑马程序员——JAVA基础之JDK1.5新特性高级for循环和可变参数
    黑马程序员——JAVA基础之Collections和Arrays,数组集合的转换
    黑马程序员——JAVA基础之Map集合
    黑马程序员——仅当源级别为 1.5 时已参数化的类型才可用的解决办法
    黑马程序员——JAVA基础之泛型和通配符
    黑马程序员——JAVA基础之Vector集合
    黑马程序员——JAVA基础之set集合
    黑马程序员——JAVA基础之List集合
    Bringing up interface eth0: Error: No suitable device found: no device found for connection 'System eth0'.
  • 原文地址:https://www.cnblogs.com/ZhuRenWang/p/4811437.html
Copyright © 2020-2023  润新知