设为首页 加入收藏

TOP

Android的布局属性中padding和margin的区别
2014-11-24 08:42:15 来源: 作者: 【 】 浏览:0
Tags:Android 布局 属性 padding margin 区别

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有边缘,页面留白的意思


借用一幅别人的图来说明



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Java PriorityQueue实现类lucene.. 下一篇Android线程异步处理之AsyncTask

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·有没有哪些高效的c++ (2025-12-27 08:20:57)
·Socket 编程时 Accep (2025-12-27 08:20:54)
·计算机网络知识点总 (2025-12-27 08:20:52)
·一篇说人话的文章, (2025-12-27 07:50:09)
·Python Web框架哪家 (2025-12-27 07:50:06)