zoukankan      html  css  js  c++  java
  • 【转载】Android的fill_parent、match_parent和wrap_content的区别

    fill_parent在全体系的Android版本中通过,match_parent使用在Android 2.2及以上版本。两者作用一致。

    1)fill_parent

    主动方:父组件

    被动方:子组件

          1.在高度或者宽度上设置为fill_parent,则子组件的高度或者长度根据父组件的值而定。通常值与父组件相等。

      2.当子组件的内容高/宽值小于父组件高/宽值,子组件内容被拉长。

          3.当子组件的内容高/宽值大于父组件高/宽值,子组件内容被裁剪。 

          fill_parent设置一个顶部布局或控件强制性让它布满整个屏幕。

    2) wrap_content

    主动方:子组件

    被动方:父组件

         1.在高度或者宽度上设置为wrap_content,则父组件的相应值由子组件的内容确定。

       2.在父组件高/宽值允许的条件下,该值取决于子组件的内容高/宽值。

         wrap_content布局指根据视图内部内容自动扩展以适应其大小。

    原文地址:http://blog.163.com/xhyzdai@126/blog/static/73253311201302310452516/ 

    官方文档的译文:

    1)fill_parent

    设置一个构件的布局为fill_parent将强制性地使构件扩展,以填充布局单元内尽可能多的空间。这跟Windows控件的dockstyle属性大体一致。设置一个顶部布局或控件为fill_parent将强制性让它布满整个屏幕。

    2) wrap_content

    设置一个视图的尺寸为wrap_content将强制性地使视图扩展以显示全部内容。以TextView和ImageView控件为例,设置为wrap_content将完整显示其内部的文本和图像。布局元素将根据内容更改大小。设置一个视图的尺寸为wrap_content大体等同于设置Windows控件的Autosize属性为True。

    下面的解释更贴切一些

    fill_parent设置一个顶部布局或控件强制性让它布满整个屏幕。

    wrap_content布局指根据视图内部内容自动扩展以适应其大小。

    以下摘自 http://blog.csdn.net/jumping_android/article/details/7397991

    1. wrap_content <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent" >       <Button         android:id="@+id/btnButton1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="Button CJP"/>   </RelativeLayout>

     

    Android的fill_parent和wrap_content的区别 - xhyzdai - 一岁一枯荣
     

    2. fill_parent – width <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent" >       <Button         android:id="@+id/btnButton1"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:text="Button CJP"/>   </RelativeLayout>

     

    Android的fill_parent和wrap_content的区别 - xhyzdai - 一岁一枯荣

     

    3. fill_parent – height <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent" >       <Button         android:id="@+id/btnButton1"         android:layout_width="wrap_content"         android:layout_height="fill_parent"         android:text="Button CJP"/>   </RelativeLayout>

     

    Android的fill_parent和wrap_content的区别 - xhyzdai - 一岁一枯荣

     

    4. fill_parent – width, height <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent" >       <Button         android:id="@+id/btnButton1"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:text="Button CJP"/>   </RelativeLayout>

     

    Android的fill_parent和wrap_content的区别 - xhyzdai - 一岁一枯荣
  • 相关阅读:
    Web开发中的服务器跳转与客户端跳转
    Linux设置程序开机自启动
    RedHat Linux6.4下安装apache服务
    FTP错误 [ftp: connect: No route to host] 解决方法
    虚拟机ping不通主机,但是主机可以ping通虚拟机(转载)
    工作中常用的Linux命令:mkdir命令
    工作中常用的Linux命令:crontab命令
    工作中常用的Linux命令:目录
    工作中常用的Linux命令:ipcs/ipcrm命令
    【CentOS】在Centos7 下无图形界面安装 Oracle11g
  • 原文地址:https://www.cnblogs.com/LiesSu/p/3835388.html
Copyright © 2011-2022 走看看