padding与margin区别

padding与margin区别

  • 2011年10月13日11:17
  • 来源:Android中文网
  • 我有话说(0)

  一直没有搞懂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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值