`

Android fill_parent、wrap_content和match_parent的区别

阅读更多

 三个属性都用来适应视图的水平或垂直大小,一个以视图的内容或尺寸为基础的布局比精确地指定视图范围更加方便。

1)fill_parent

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

2) wrap_content

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

3)match_parent
   Android2.2中match_parent和fill_parent是一个意思 .两个参数意思一样,match_parent更贴切,于是从2.2开始两个词都可以用。那么如果考虑低版本的使用情况你就需要用fill_parent了

分享到:
评论

相关推荐

    Android 教程 PDF

    可以设置为`"fill_parent"`(占据父容器全部空间)、`"match_parent"`(与`"fill_parent"`等效)或`"wrap_content"`(根据内容自动调整尺寸)。 **1.2 示例代码** ```xml <LinearLayout xmlns:android=...

    Android学习笔记

    有三个值match_parent、fill_parent、wrap_content. 其中match_parent和fill_parent的意义相同,但官方更推荐match_parent. match_parent表示让当前控件的大小和父布局的大小一样,也就是由父布局来决定当前控件的...

    Android布局

    - **android:layout_width** 和 **android:layout_height**:用于设定视图的宽高,可以选择`wrap_content`(视图自动调整大小以匹配内容)或`match_parent`(视图大小与父容器相同)。 **示例代码**: ```xml ...

    Android开发教程之Android 五大布局--千锋培训

    在Android开发中,布局管理器是构建用户界面的关键组件,它们负责组织和定位应用程序中的视图元素。本教程将深入探讨Android的五大布局:FrameLayout、LinearLayout、RelativeLayout、TableLayout以及AbsoluteLayout...

    Android控件大全以及各布局空间的使用方式

    - `android:layout_width` 和 `android:layout_height`: 设置布局的宽度和高度,可以使用 `fill_parent` 或 `match_parent` 让布局填充整个父容器,`wrap_content` 让布局根据内容自动调整大小,也可以直接指定像素...

    Android的Layout完全介绍

    android:layout_width="fill_parent" android:layout_height="fill_parent"> android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="I am textview 1" /> android:...

    Android页面布局总结

    `wrap_content`用于使视图的大小适应其内容,而`match_parent`(等同于`fill_parent`)则使视图填充整个父容器。 通过以上介绍,我们可以看出,选择合适的布局类型对于优化用户界面至关重要。每种布局都有其独特的...

    android移动应用开发-报告书.docx

    android:layout_height="match_parent" android:orientation="vertical" android:background="#C0C0C0"> android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="wrap_...

    Android学习指南之Layout 布局--千锋培训

    - `Fill Mode`:指定子视图的尺寸,可以是具体的像素值、`wrap_content`(根据内容自动调整大小)或`fill_parent`(占据剩余空间)。 - `Weight`:权重属性,用于按比例分配子视图的大小。当多个子视图具有不同的...

    Android中Button样式新方法

    在布局文件中,我们可以创建一个LinearLayout,设置其宽度为fill_parent(或match_parent),高度为wrap_content,以便适应内容大小。通过设置orientation属性为horizontal,我们可以让内部的组件水平排列。同时,...

    android初学者开发笔记

    android:layout_height="match_parent"> android:layout_width="100dp" android:layout_height="100dp" android:background="@color/colorPrimary" android:layout_gravity="center" /> android:layout_...

    Android TabHost组件使用方法详解

    android:layout_width="match_parent" android:layout_height="match_parent"> android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> android:id=...

    05-RadioButton和RadioGroup

    android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_...

    android中的左右滑屏实现

    android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editText1"> <!-- layout2.xml --> <LinearLayout xmlns:android=...

    Android中使用LinearLayout完成的内蒙古导览项目的代码清单 .pdf

    `layout_width`和`layout_height`都设置为`fill_parent`,表示占据父容器的全部宽度和高度。`orientation`属性设置为`vertical`,意味着子视图将按垂直方向排列。 在LinearLayout中,我们有一个TextView和一个...

    Android 控件说明

    - `layout_width` 和 `layout_height`:用于定义视图的宽度和高度,可以使用`match_parent`(旧称`fill_parent`)来匹配父视图大小,或`wrap_content`来让视图根据其内容自动调整大小,也可以直接指定像素值。...

    Android应用开发-购物信息存储界面开发.pptx

    android:layout_width="match_parent" android:layout_height="wrap_content"> <!-- 商品行 --> android:layout_width="wrap_content" android:layout_height="wrap_content"> android:text="商品名称" ...

Global site tag (gtag.js) - Google Analytics