Differences between android: padding and android: layout_margin,
Margin and padding are the two most commonly used attributes in the Separation element.
◆ Padding attributes:
The Padding attribute is used to describe how much space is inserted between the border of an element and its child elements. It is divided into upper (padding-top) and lower (padding-bottom) left (padding-left) and a shortcut padding
◆MarginAttribute:
The Margin attribute is used to describe how much space is inserted between the border of an element and the border containing its parent element. Similar to the padding attribute, it is also divided into the upper (margin-top) right (margin-right) lower (margin-bottom) left (margin-left) and a shortcut margin
Android: layout_margin is the extra space for setting the top, bottom, and left borders of a view.
Android: padding is used to set the distance between the content and the border of the view.
In LinearLayout, RelativeLayout, and TableLayout, both attributes are valid.
In FrameLayout, android: layout_margin is invalid because the elements in FrameLayout are drawn from the upper left corner.
In AbsoluteLayout, there is no android: layout_margin attribute
Android: layout_alignParentRight = "true" attribute is the parent container of the Child control. The parent container must be RelativeLayout.
I have never understood the difference between Android: padding and android: layout_margin. In fact, the concept is very simple. padding describes the problem from the perspective of the parent view, it specifies the distance between the content in it and the parent view. Margin describes the problem from the perspective of itself and specifies the distance between itself and other views (up and down). If there is only one view at the same level, the effect is basically the same as that of padding. For example, my XML layout code is as follows:
<?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>
<?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, which are clearly marked as differences in the figure.