如何区别fill_parent和wrap_content

 时间:2026-04-21 16:42:59

在Android布局文件中定义视图垂直或水平大小:

android:layout_width和android_layout_height的属性有fill_parent、wrap_content和match_parent

fill_parent、wrap_content和match_parent的区别:

1、wrap_content:表示大小刚好足够显示当前控件里的内容

<Button

        android:id="@+id/button1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentLeft="true"

        android:layout_alignParentTop="true"

        android:text="传递数据" />

如何区别fill_parent和wrap_content

2、fill_parent和match_parent:

Android中fill_parent和match_parent(从Android2.2)是一样的。

为了兼容低版本,建议使用fill_parent

设置布局/控件为fill_parent将强制性让它布满整个屏幕或填满父控件的空白

  <Button

        android:id="@+id/button1"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:layout_alignParentLeft="true"

        android:layout_alignParentTop="true"

        android:text="传递数据" />

如何区别fill_parent和wrap_content

  • Android Studio怎么查看SDK版本
  • github下载按钮在哪
  • Windows11安卓子系统文件路径查看方法
  • android studio怎么安装
  • IntelliJ IDEA怎么设置打开软件自动打开项目
  • 热门搜索
    瑞雪兆丰年什么意思 丹参的功效与作用 育儿知识网 香蕉皮的功效与作用 五年级下册数学知识点总结 不可名状什么意思 九上历史知识点 泡打粉的作用 十万个冷知识 此去经年什么意思