1. Here we record a few vague concepts:
Padding MarginIt is the meaning of the margin. The key issue is to understand what the margin is.
PaddingIs the margin of the control content relative to the control edge.
MarginIs the margin of the control edge relative to the parent space.
Android: The gravity attribute limits the content of the view. For example, you can set the text on the button to the left and right of the view.
Android: layout_gravity is used to set the position of the child view in the view relative to the parent view. for example, if a button is in linearlayout, you can set it in linearlayout by placing it on the left and right.
The following is an example:
<?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>
Then I will get the following results. The differences are clearly marked in the figure.
Difference between padding and margin (transferred online)