如何区别fill_parent和wrap_content

 时间:2026-02-13 16:19:53

在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怎么设置打开软件自动打开项目
  • 热门搜索
    老鸭煲的做法 长智齿牙龈肿痛怎么办 嵇怎么读 平鱼的做法 广东肠粉的做法 美食小吃做法大全 上汤娃娃菜的家常做法 油焖茄子的做法 腊肠做法 蟹炒年糕的做法