什么是FILL_PARENT和WRAP_CONTENT之间的区别?区别、FILL_PARENT、WRAP_CONTENT

2023-09-12 00:58:59 作者:我不蛇蝎怎能毁你所爱

在Android的布局小窗口部件的时候,有什么FILL_PARENT和WRAP_CONTENT之间的区别?

In Android, when layout out widgets, what's the difference between fill_parent and wrap_content?

有任何文档,你可以点?我感兴趣的理解非常好。

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

推荐答案

任一属性可应用到视图的(可视控件)的水平或垂直大小。它是用来设置一个基于要么它的内容或它的大小的父布局,而不是明确指定一个维度视图或布局大小。

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 (德pcated和API级别8改名 MATCH_PARENT $ P $和更高版本)

fill_parent (deprecated and renamed MATCH_PARENT in API Level 8 and higher)

设置小部件FILL_PARENT将迫使它扩大到占据尽可能多的空间,是它被放置在布局元素中可用的布局。这是大致相当于一个Windows窗体控件的dockstyle设置为填写。

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

设置视图的大小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窗体控件的自动调整属性设置为True等效。

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

在线文档

有在Android code文档一些细节这里。

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