MARGIN 与padding区别
2013-03-01 14:27
375 查看
之前一直没有搞懂android:padding和android:layout_margin的区别,其实概念很简单,padding是站在父view的角度描述问题,它规定它里面的内容必须与这个父view边界的距离。margin则是站在自己的角度描述问题,规定自己和其他(上下左右)的view之间的距离,如果同一级只有一个view,那么它的效果基本上就和padding一样了。例如我的XML layout代码如下:
[xhtml] view plaincopy
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:paddingBottom="10dip"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="@string/hello"
android:paddingLeft="50dip"
android:paddingRight="50dip"
android:paddingTop="50dip"
android:paddingBottom="50dip"
android:layout_marginBottom="10dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="@string/hello"
android:paddingLeft="50dip"
android:paddingRight="50dip"
android:paddingTop="50dip"
android:paddingBottom="50dip"
android:layout_marginBottom="10dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="@string/hello"
android:paddingLeft="50dip"
android:paddingRight="50dip"
android:paddingTop="50dip"
android:paddingBottom="50dip"
android:layout_marginBottom="10dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="@string/hello"
android:paddingLeft="50dip"
android:paddingRight="50dip"
android:paddingTop="50dip"
android:paddingBottom="50dip"
android:layout_marginBottom="10dip"
/>
</LinearLayout>
那么我会得到如下的效果,图上已经很明确的标出来区别咯。
[xhtml] view plaincopy
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:paddingBottom="10dip"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="@string/hello"
android:paddingLeft="50dip"
android:paddingRight="50dip"
android:paddingTop="50dip"
android:paddingBottom="50dip"
android:layout_marginBottom="10dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="@string/hello"
android:paddingLeft="50dip"
android:paddingRight="50dip"
android:paddingTop="50dip"
android:paddingBottom="50dip"
android:layout_marginBottom="10dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="@string/hello"
android:paddingLeft="50dip"
android:paddingRight="50dip"
android:paddingTop="50dip"
android:paddingBottom="50dip"
android:layout_marginBottom="10dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="@string/hello"
android:paddingLeft="50dip"
android:paddingRight="50dip"
android:paddingTop="50dip"
android:paddingBottom="50dip"
android:layout_marginBottom="10dip"
/>
</LinearLayout>
那么我会得到如下的效果,图上已经很明确的标出来区别咯。
相关文章推荐
- android:paddingLeft与android:layout_marginLeft的区别
- css中padding、margin属性的区别和详解
- android:padding和android:margin的区别
- padding-top和margin-top的区别
- padding与margin的区别
- Android中gravity、layout_gravity、padding、margin的区别小结
- margin和padding的区别
- margin, padding,border之间的区别
- layout_gravity与gravity的区别,和padding margin的区别
- android:padding和android:layout_margin的区别
- margin 和 padding 的区别
- android:padding和android:layout_margin区别
- Android padding和margin的区别
- 布局中的Padding与Margin的区别
- ndroid:paddingLeft与android:layout_marginLeft的区别
- Android中gravity与layout_gravity的区别--Padding 与 margin 区别
- padding和margin区别
- Android android:paddingLeft与android:layout_marginLeft的区别
- android:padding和android:margin的区别
- (转)android:padding和android:margin的区别