视图的填充和边距之间的区别
视图的边距和填充有什么区别?
What is the difference between a View's Margin and Padding?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
视图的边距和填充有什么区别?
What is the difference between a View's Margin and Padding?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(15)
为了帮助我记住衬垫的含义,我想到了一件带有许多厚棉衬垫的大衣。我在外套里面,但我和我的棉衣是在一起的。我们是一个单位。
但要记住边距,我会想到,“嘿,给我一些边距!”这是我和你之间的空白空间。不要进入我的舒适区——我的边缘。
为了更清楚地说明,这是
TextView
中的填充和边距的图片:上面图像的 xml 布局
相关
To help me remember the meaning of padding, I think of a big coat with lots of thick cotton padding. I'm inside my coat, but me and my padded coat are together. We're a unit.
But to remember margin, I think of, "Hey, give me some margin!" It's the empty space between me and you. Don't come inside my comfort zone -- my margin.
To make it more clear, here is a picture of padding and margin in a
TextView
:xml layout for the image above
Related
内边距是边框内部、边框与实际视图内容之间的空间。请注意,填充完全围绕内容:顶部、底部、右侧和左侧都有填充(可以是独立的)。
边距是边框外、边框与该视图旁边的其他元素之间的空间。在图像中,边缘是整个对象外部的灰色区域。请注意,与填充一样,边距完全围绕内容:顶部、底部、右侧和左侧都有边距。
一张图片包含超过 1000 个单词(摘自 Margin Vs Padding - CSS 属性):
Padding is the space inside the border, between the border and the actual view's content. Note that padding goes completely around the content: there is padding on the top, bottom, right and left sides (which can be independent).
Margins are the spaces outside the border, between the border and the other elements next to this view. In the image, the margin is the grey area outside the entire object. Note that, like the padding, the margin goes completely around the content: there are margins on the top, bottom, right, and left sides.
An image says more than 1000 words (extracted from Margin Vs Padding - CSS Properties):
填充位于视图内部。
边距位于视图之外。
这种差异可能与背景或尺寸属性有关。
Padding is inside of a View.
Margin is outside of a View.
This difference may be relevant to background or size properties.
内边距在视图内,边距在视图外。填充可用于所有视图。根据视图的不同,填充和边距之间可能存在也可能不存在视觉差异。
例如,对于按钮,特征按钮背景图像包括填充,但不包括边距。换句话说,添加更多的内边距会使按钮在视觉上看起来更大,而添加更多的边距只会使按钮和下一个控件之间的间隙更宽。
另一方面,对于 TextView 来说,填充和边距的视觉效果是相同的。
margin 是否可用由视图的容器决定,而不是由视图本身决定。在
LinearLayout
中支持边距,在AbsoluteLayout
中(现在已被认为已过时)- 不支持。Padding is within the view, margin is outside. Padding is available for all views. Depending on the view, there may or may not be a visual difference between padding and margin.
For buttons, for example, the characteristic button background image includes the padding, but not the margin. In other words, adding more padding makes the button look visually bigger, while adding more margin just makes the gap between the button and the next control wider.
For
TextView
s, on the other hand, the visual effect of padding and margin is identical.Whether or not margin is available is determined by the container of the view, not by the view itself. In
LinearLayout
margin is supported, inAbsoluteLayout
(considered obsolete now) - no.下图将让您了解填充和边距 -
Below image will let you understand the padding and margin-
填充是指小部件和小部件原始框架之间的空间。但边距是小部件的原始框架与其他小部件框架之间的空间。。
Padding means space between widget and widget original frame. But the margin is space between widget's original frame to boundaries other widget's frame..
填充
Padding 位于 View 内部。例如,如果您指定
android:paddingLeft=20dp
,则视图内的项目将从左侧以20dp
宽度排列。您也可以使用paddingRight
、paddingBottom
、paddingTop
分别从右、下、上进行填充。保证金
边距位于
视图
之外。例如,如果您指定android:marginLeft=20dp
,则视图将排列在左侧20dp
之后。Padding
Padding is inside of a View.For example if you give
android:paddingLeft=20dp
, then the items inside the view will arrange with20dp
width from left.You can also usepaddingRight
,paddingBottom
,paddingTop
which are to give padding from right, bottom and top respectively.Margin
Margin is outside of a
View
. For example if you giveandroid:marginLeft=20dp
, then the view will be arranged after20dp
from left.填充是边框内部与实际图像或单元格内容之间的空间。
边距是边框外部、边框与该对象旁边的其他元素之间的空间。
Padding is the space inside the border between the border and the actual image or cell contents.
Margins are the spaces outside the border, between the border and the other elements next to this object.
有时,您可以通过仅使用填充或边距来实现相同的结果。示例:
假设视图 X 包含视图 Y(又名:视图 Y 在视图 X 内部)。
-Margin=30 的视图 Y 或 Padding=30 的视图 X 将获得相同的结果:视图 Y 的偏移量为 30。
Sometimes you can achieve the same result by playing only with padding OR margin. Example :
Say View X contains view Y (aka : View Y is inside View X).
-View Y with Margin=30 OR View X with Padding=30 will achieve the same result: View Y will have an offset of 30.
除了上述所有正确答案之外,另一个区别是内边距增加了视图的可点击区域,而边距则增加了视图的可点击区域。不是。。如果您有一个较小的可点击图像但想让点击处理程序宽容,这非常有用。
例如,请查看带有
ImageView
(Android 图标)的布局图像,其中我将paddingBotton
设置为100dp
(图像为库存启动器 mipmapic_launcher
)。通过附加的点击处理程序,我可以点击图像外部和下方,并且仍然注册一次点击。In addition to all the correct answers above, one other difference is that padding increases the clickable area of a view, whereas margins do not. This is useful if you have a smallish clickable image but want to make the click handler forgiving.
For eg, see this image of my layout with an
ImageView
(the Android icon) where I set thepaddingBotton
to be100dp
(the image is the stock launcher mipmapic_launcher
). With the attached click handler I was able to click way outside and below the image and still register a click.简单来说:
In simple words:
我们假设视图中有一个按钮,视图的大小为 200 x 200,按钮的大小为 50 x 50,按钮标题为 HT。现在margin和padding之间的区别是,您可以在视图中设置按钮的边距,例如从左侧20,从顶部20,而padding会调整按钮或文本视图中的文本位置等。例如,padding值为从左边算起20,所以它会调整文本的位置。
Let's just suppose you have a button in a view and the size of the view is 200 by 200, and the size of the button is 50 by 50, and the button title is HT. Now the difference between margin and padding is, you can set the margin of the button in the view, for example 20 from the left, 20 from the top, and padding will adjust the text position in the button or text view etc. for example, padding value is 20 from the left, so it will adjust the position of the text.
边距是指元素外部的额外空间。填充是指元素内的额外空间。边距是控件周围的额外空间。填充是控件内部的额外空间。
使用白色填充很难看出边距和填充的差异,但使用彩色填充时您可以很好地看到它。
Margin refers to the extra space outside of an element. Padding refers to the extra space within an element. The margin is the extra space around the control. The padding is extra space inside the control.
It's hard to see the difference with margin and padding with a white fill, but with a colored fill you can see it fine.
简单来说:
填充会改变盒子的大小(带有某些东西)。
margin 改变不同盒子之间的空间
In simple words:
padding changes the size of the box (with something).
margin changes the space between different boxes
Padding 用于在视图及其内容之间添加空白区域。
边距用于在不同视图之间添加空间。
对于填充和边距,我们有两种方法来设置它们,
所有边具有相等值:
您可以使用
android:padding="15dp"
用于设置所有边 15dp 的内边距和
android:layout_margin="15dp"
用于设置所有边 15dp 的边距具有特定值的边:
Padding
android:paddingBottom
设置底部边缘的填充android:paddingStart
设置起始边缘的填充意味着在视图的左侧android:paddingEnd
设置底部边缘的填充结束边缘表示在视图的右侧android:paddingTop
设置顶部边缘的填充Margin
android:layout_marginBottom
指定底部的额外空间此视图的侧面。android:layout_marginEnd
指定末端的额外空间,即在此视图的右侧。android:layout_marginStart
指定起始侧的额外空间,即在此视图的左侧。android:layout_marginTop
指定此视图顶部的额外空间。Padding is used to add a blank space between a view and its contents.
Margin is used to add a space between different views.
For both padding and margin, we have two way to set those,
All sides with equal values:
You can use
android:padding="15dp"
for setting padding of 15dp all the sidesand
android:layout_margin="15dp"
for setting margin of 15dp all the sidesSides with specific values:
Padding
android:paddingBottom
Sets the padding at the bottom edgeandroid:paddingStart
Sets the padding at the start edge means at the left side of viewandroid:paddingEnd
Sets the padding at the end edge means at the right side of viewandroid:paddingTop
Sets the padding at the top edgeMargin
android:layout_marginBottom
Specifies extra space on the bottom side of this view.android:layout_marginEnd
Specifies extra space on the end side, means at the right side of this view.android:layout_marginStart
Specifies extra space on the start side, means at the left of this view.android:layout_marginTop
Specifies extra space on the top side of this view.