Margin和Padding的区别

Margin和Padding的区别

一、简介

二、实例

效果图

代码

/MarginAndPadding/res/layout/activity01.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical" >
 6 
 7     <TextView 
 8         android:layout_width="wrap_content"
 9         android:layout_height="wrap_content"
10         android:background="@android:color/darker_gray"
11         android:text="margin案例一"
12         android:layout_marginTop="30dp"
13         android:layout_marginLeft="30dp"
14         />    
15         
16     <TextView 
17         android:layout_width="wrap_content"
18         android:layout_height="wrap_content"
19         android:background="@android:color/darker_gray"
20         android:text="margin案例二"
21         android:layout_margin="60dp"
22         />    
23         
24     <TextView 
25         android:layout_width="wrap_content"
26         android:layout_height="wrap_content"
27         android:background="@android:color/darker_gray"
28         android:text="padding案例一"
29         android:layout_alignParentRight="true"
30         android:paddingTop="30dp"
31         android:paddingLeft="30dp"
32         />    
33         
34     
35 </RelativeLayout>
原文地址:https://www.cnblogs.com/Renyi-Fan/p/7290115.html