fill_parent 和 wrap_content 有什么区别? [英] What's the difference between fill_parent and wrap_content?

查看:22
本文介绍了fill_parent 和 wrap_content 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Android 中,当布局小部件时,fill_parent(API 级别 8 及更高版本中的 match_parent)和 wrap_content 之间有什么区别?

In Android, when layout out widgets, what's the difference between fill_parent (match_parent in API Level 8 and higher) and wrap_content?

有什么文档可以指点一下吗?我有兴趣很好地理解它.

Is there any documentation where you can point to? I'm interested in understanding it very well.

推荐答案

任一属性都可以应用于 View 的(视觉控制)水平或垂直尺寸.它用于根据其内容或其父布局的大小设置视图或布局的大小,而不是明确指定尺寸.

Either attribute can be applied to View's (visual control) horizontal or vertical size. It's used to set a View or Layouts size based on either it's contents or the size of it's parent layout rather than explicitly specifying a dimension.

fill_parent(在 API 级别 8 及更高版本中已弃用并重命名 MATCH_PARENT)

将小部件的布局设置为 fill_parent 将强制它展开以占据放置它的布局元素内可用的空间.这大致相当于将 Windows 窗体控件的停靠样式设置为 填写.

Setting the layout of a widget to fill_parent will force it to expand to take up as much space as is available within the layout element it's been placed in. It's roughly equivalent of setting the dockstyle of a Windows Form Control to Fill.

将顶级布局或控件设置为 fill_parent 将强制它占据整个屏幕.

Setting a top level layout or control to fill_parent will force it to take up the whole screen.

wrap_content

将视图的大小设置为 wrap_content 将强制它扩展到足以包含它包含的值(或子控件)的程度.对于控件——比如文本框 (TextView) 或图像 (ImageView)——这将包裹显示的文本或图像.对于布局元素,它将调整布局大小以适应作为其子项添加的控件/布局.

Setting a View's size to wrap_content will force it to expand only far enough to contain the values (or child controls) it contains. For controls -- like text boxes (TextView) or images (ImageView) -- this will wrap the text or image being shown. For layout elements it will resize the layout to fit the controls / layouts added as its children.

这大致相当于将 Windows 窗体控件的 Autosize 属性设置为 True.

It's roughly the equivalent of setting a Windows Form Control's Autosize property to True.

在线文档

Android 代码文档中有一些详细信息此处.

There's some details in the Android code documentation here.

这篇关于fill_parent 和 wrap_content 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆