<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#000000"
/>
</LinearLayout>
</RelativeLayout>
Padding是内部的边距,margin是外部的边距。(这里的内部与外部是相对于定义Padding或者margin的控件而言的,谁定义,谁来用)
layout_margin
直接上图,注意代码中光标的位置:
上面三张图光标都停在了layout_margin定义的控件上。从右边的蓝色位置可知,margin表示当前控件对与外部的距离,这里的外部都是其父控件而已。
Padding
这里光标都放在了Padding定义控件的子控件中,右边的效果与刚才的一样,表示Padding是用在内部的边距上。Android官网上说Describes a padding to be applied along the edges inside a box.(描述沿盒子内的边缘施加的填充物。)就是这个意思,常用在父布局中,描述其子布局距其的位置。