在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. 生成验证码tp

    js里拼接随机数 页面上链接 去掉后缀名

  2. stegsolve使用探究

    应该也不是工具的问题吧,更多的是图片.但是不知道咋取就写工具了. 比如:http://ctf5.shiyanbar.com/stega/chromatophoria/steg.png 我在想为毛要选择 ...

  3. 64_t2

    texlive-biblatex-chem-doc-svn42065-33.fc26.2.no..> 24-May-2017 15:44 1044190 texlive-biblatex-che ...

  4. 在ubuntu中安装puppeteer

    https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md 早些时候puppeteer刚出来,在vps上 ...

  5. 模块定义文件.def

    一作用 DLL中导出函数的声明有两种方式:一种为在函数声明中加上__declspec(dllexport),这里不再举例说明:另外一种方式是采用模块定义(.def) 文件声明,.def文件为链接器提供 ...

  6. POJ 3169 Layout (spfa+差分约束)

    题目链接:http://poj.org/problem?id=3169 题目大意:n头牛,按编号1~n从左往右排列,可以多头牛站在同一个点,给出ml行条件,每行三个数a b c表示dis[b]-dis ...

  7. gc 调优记录

    qps 10,0000 -Xms10240m -Xmx10240m -XX:NewRatio=5 -XX:SurvivorRatio=6 2017-12-19T15:10:14.539+0800: 1 ...

  8. C#窗口矩形区域着色

    C#写的一个GUI窗口,有几百个矩形区域.每个矩形区域的颜色随时都可能改变,并且多次改变. 我放弃使用label绘制矩形,因为效果不好.拖控件的界面使用power packs中的rectanglesh ...

  9. css3 图标变大变小在变小变大

    css3 @-webkit-keyframes anLoca { from { -webkit-transform: scale3d(1, 1, 1); } to { -webkit-transfor ...

  10. 解决 VUE 微信 IOS 路由跳转问题

    watch: { "$route"(){ if (/iPhone|mac|iPod|iPad/i.test(navigator.userAgent)) { location.hre ...