android 中 padding与margin的区别

android:padding和android:layout_margin的区别,其实概念很简单,padding是站在父view的角度描述问题,它规定它里面的内容必须与这个父view边界的距离margin则是站在自己的角度描述问题,规定自己和其他(上下左右)的view之间的距离,如果同一级只有一个view,那么它的效果基本上就和padding一样了。例如我的XML layout代码如下:

<?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 中 padding与margin的区别_第1张图片

更多相关文章

  1. Android v4、v7、v13 的区别
  2. Android 1.5和Android 2.1在相对布局(RelativeLayout)上的区别
  3. android:layout_alignleft layout_toleftof区别,详解RelativeLayo
  4. Android SystemProperties.get()和System.getProperty()的区别
  5. android:layout_marginLeft指该控件距离边父控件的边距, android:
  6. android Thread和Runnable的区别
  7. Android计算地图上两点距离

随机推荐

  1. Android(安卓)SQLite 数据库详细介绍
  2. Android加载Bitmap出现OutofMemoryError
  3. 直接用 Chrome 扩展来回复 Android(安卓)
  4. Android中的dip,dp,sp,px
  5. Out of Milk Shopping List 用Android打
  6. Android(安卓)UI开发第十四篇――可以移
  7. android 获取网络图片缓存(内存—>文件—>
  8. 两分钟搞定android JNI
  9. 【Android(安卓)Training - 05】与其他Ap
  10. Android(安卓)中 Activity的内存泄漏,原因