在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将按钮显示为能够装下其内容。

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的宽度一样,单高度依然是保持在紧紧能容纳下内容。
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的宽度一样,单高度依然是保持在紧紧能容纳下内容。
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有多种设备屏幕尺寸。我们不知道我们的应用程序会跑在哪一种尺寸的Android设备上。。。。

[转]Android 中fill_parent与wrap_content的区别的更多相关文章

  1. android布局 - fill_parent/match_paren/wrap_content的区别

    三个属性都用来适应视图的水平或垂直大小,一个以视图的内容或尺寸为基础的布局比精确地指定视图范围更加方便. 1)fill_parent 设置一个构件的布局为fill_parent将强制性地使构件扩展,以 ...

  2. fill_parent和wrap_content的区别

    在Android布局文件中定义视图垂直或水平大小: android:layout_width和android_layout_height的属性有fill_parent.wrap_content和mat ...

  3. 【整理】Android中的gravity和layout_gravity区别

    [背景] 在Android中,想要设置个按钮的水平对齐,都累死了: [已解决]ADT中已设置TableLayout布局的情况下如何设置按钮居中对齐    所以现在有必要搞清楚,到底gravity和la ...

  4. Android中style和theme的区别

    在学习Xamarin android的过程中,最先开始学习的还是熟练掌握android的六大布局-LinearLayout .RelativeLayout.TableLayout.FrameLayou ...

  5. Android中px和dip的区别

    在Android手机的诞生之初,由于Android系统是开源的,一开始便有众多的OEM厂商对Android手机进行深度定制,于是乎Android手机的皮肤和屏幕大小都变得百花齐放,这可苦逼了我们这群开 ...

  6. 浅谈Android中Serializable和Parcelable使用区别

    版权声明:本文出自汪磊的博客,转载请务必注明出处. 一.概述 Android开发的时候,我们时长遇到传递对象的需求,但是我们无法将对象的引用传给Activity或者Fragment,我们需要将这些对象 ...

  7. Android中Popupwindow和Dialog的区别

    Android中的对话框有两种:PopupWindow和AlertDialog.它们都可以实现弹窗功能,但是他们之间有一些差别,下面总结了一点. (1)Popupwindow在显示之前一定要设置宽高, ...

  8. 【Android】android中Invalidate和postInvalidate的区别

    Android中实现view的更新有两组方法,一组是invalidate,另一组是postInvalidate,其中前者是在UI线程自身中使用,而后者在非UI线程中使用. Android提供了Inva ...

  9. android中Invalidate和postInvalidate的区别

    Android中实现view的更新有两组方法,一组是invalidate,另一组是postInvalidate,其中前者是在UI线程自身中使用,而后者在非UI线程中使用. Android提供了Inva ...

随机推荐

  1. php常用表单验证类用法实例

    <?php /** * 页面作用:常用表单验证类 * 作 者:欣然随风 * QQ:276624915 */ class class_post { //验证是否为指定长度的字母/数字组合 func ...

  2. struts2 constant详解

    <!-- 指定Web应用的默认编码集,相当于调用 HttpServletRequest的setCharacterEncoding方法 -->        <constant nam ...

  3. perl6正则 4: before / after 代码断言: <?{}> / <!{}>

    <?before> <? befor XXX> 某字符在 xxx 之前 <?after > <?after XXX> 某字符之后有XXX 对应的取反分别 ...

  4. 33、求按从小到大的顺序的第N个丑数

    一.题目 把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数. 二.解法 ...

  5. tp5 r3 一个简单的SQL语句调试实例

    tp5 r3 一个简单的SQL语句调试实例先看效果核心代码 public function index() { if (IS_AJAX && session("uid&quo ...

  6. 21.Merge Two Sorted Lists---《剑指offer》面试17

    题目链接:https://leetcode.com/problems/merge-two-sorted-lists/description/ 题目大意: 给出两个升序链表,将它们归并成一个链表,若有重 ...

  7. 141.Linked List Cycle---双指针

    题目链接 题目大意:给出一个链表,判断该链表是否有环,空间复杂度最好控制在o(1) 这个题没有给测试用例,导致没太明白题目意思,看了题解,用了两种方法示例如下: 法一(借鉴):利用两个指针,一个指针步 ...

  8. 56.Merge Intervals---贪心---《编程之美》2.19区间重合判断

    题目链接:https://leetcode.com/problems/merge-intervals/description/ 题目大意:给出一串list,里面装interval类,这个类里有star ...

  9. Loadrunner脚本学习总结

    1.1      web脚本录制选择Web(HTTP/HTML)协议: 注意录制脚本前选择如下协议: 1.2      脚本如果需要使用如下函数: web_reg_save_param.web_fin ...

  10. Java容器---Arrays & Collections工具类

    1.Array & Arrays 与Collection & Collections区别 (1)Collection": 是一个接口,与其子类共同组成一个Collection ...