Android中的padding和margin的区别

在Android的布局中,常常有人将padding和margin搞混,他们其实不一样的,padding是该控件的内部距离。

magin是该控件与其他控件之间的距离。例如

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_blue_light"
    android:orientation="vertical" >
    
    <TextView

   android:padding="10dp"
        android:layout_margin="10dp"
        android:background="@android:color/holo_green_light"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/test"/>

</LinearLayout>

得到的布局如下:

原文地址:https://www.cnblogs.com/suicode/p/8685869.html