43 android
我在SO上提到过问题.还检查了答案:
填充是边框内,边框和实际视图内容之间的空间.请注意,填充完全围绕内容:顶部,底部,右侧和左侧有填充(可以是独立的).
边距是边框之外,边框和此视图旁边的其他元素之间的空格.在图像中,边距是整个对象外部的灰色区域.请注意,与填充一样,边距完全围绕内容:顶部,底部,右侧和左侧都有边距.
此外,更多关于填充和边距来自:
http://developer.android.com/reference/android/view/View.html
http://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html
但填充和边距之间的根本区别是什么?行为会因OS和设备而异吗?
我有一个正常,简单的布局.没有问题的代码,使用布局文件夹 - 布局和布局-sw600dp加上drawables-4dpi.没有边距或填充不能进行布局,哪一个更合适?
Kas*_*zar 61
余量
边距构成元素之间的垂直和水平区域.如果元素周围没有边距,它们将相互碰撞.换句话说,他在元素之外或之间的空间是构成边缘区域的空间.

填充
元素的填充是围绕目标元素的内容区域设置的水平和垂直空间.因此填充在盒子的内部,而不是外部.

Par*_*rth 40
Padding适用于内部/内部组件.例如.TextView,Button,EditText等
如.文字和边框之间的空格
Margin适用于组件的外部.
例如.屏幕左边缘与组件边框之间的空间
视觉表现非常出色:视图的填充和边距之间的差异
用Padding,我已经看到在2.2,2.3的差,并说4.3,4.4
在这种情况下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="ASDFGHJKL" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:text="@string/hello_world" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
另外,请检查维度的使用:
http://developer.android.com/guide/topics/resources/more-resources.html
http://developer.android.com/samples/BasicSyncAdapter/res/values/dimen.html
Xar*_*mer 24
简单来说..如果你想把你的小部件像TextView一样,EditText远离其他.您应该使用顶部,右侧,左侧,底部的边距.
通过增加填充,它将增加内部间距,而不会使小部件远离其他部分.

与按钮类似,例如,特征按钮背景图像包括填充,但不包括边距.换句话说,添加更多填充使按钮看起来更大,而添加更多边距只会使按钮和下一个控件之间的间隙变宽.