android的布局属性中padding和margin的区别
google的android文档里的解释:
public static final int padding
Since: API Level 1 Sets the padding, in pixels, of all four edges. Padding is defined as space between the edges of the view and the view's content. A views size will include it's padding. If a background
is provided, the padding will initially be set to that (0 if the drawable does not have padding). Explicitly setting a padding value will override the corresponding padding found in the background.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).
This may also be a reference to a resource (in the form "@[package:]type:name
") or theme attribute (in the form "?[package:][type:]name
") containing a value of this type.
Constant Value: 16842965 (0x010100d5) 再看margin,以marginBottom 举例 android:layout_marginBottom
Since: API Level Specifies extra space on the bottom side of this view. This space is outside this view's bounds.
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).
This may also be a reference to a resource (in the form "@[package:]type:name
") or theme attribute (in the form "?[package:][type:]name
") containing a value of this type.
This corresponds to the global attribute resource symbol layout_marginBottom
.
Related Methods
- setMargins(int,int,int,int)
所以padding是定义控件自己的内容和控件边缘之间的距离,padding有填充填料的意思,而margin是在说控件的四个边缘之外的距离,指的是和别的控件之间的距离,margin有边缘,页面留白的意思
借用一幅别人的图来说明
background
is provided, the padding will initially be set to that (0 if the drawable does not have padding). Explicitly setting a padding value will override the corresponding padding found in the background. 14.5sp
". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters). @[package:]type:name
") or theme attribute (in the form "?[package:][type:]name
") containing a value of this type. 14.5sp
". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters). @[package:]type:name
") or theme attribute (in the form "?[package:][type:]name
") containing a value of this type. layout_marginBottom
.更多相关文章
- Android 控件界面转成Bitmap
- android UI控件之webview控件使用实例:加载网页到webview中
- Android - 获取控件(包括状态栏与标题栏)宽高
- android获取控件宽高
- android日期控件显示
- Android 复用自制的控件(2)
- Android控件之——输入框TextInputLayout、TextInputEditText的
- android scrollview滑动时悬浮部分控件
- Android控件属性android:fitsSystemWindows="true"的坑