Margin and padding are the most commonly used two attributes in a separate element
Padding properties:
The Padding property is used to describe how much space is inserted between the bounding rectangle of an element and its child elements. It is divided up (padding-top) Right (Padding-right) (Padding-bottom) to the left (Padding-left) and a shortcut padding
Margin Property:
The margin property is used to describe how much space is inserted between the bounding rectangle of an element and the bounding rectangle of the parent element that contains it, similar to the Padding property. It is also divided into the upper (Margin-top) Right (Margin-right) (Margin-bottom) left (Margin-left) and a shortcut margin
Android:layout_margin is the extra space to set the upper and lower left and right borders of the view
Android:padding is the distance that sets the border of the content relative to the view
In LinearLayout, Relativelayout, Tablelayout, these 2 properties are all set to be valid.
In Framelayout, Android:layout_margin is invalid because the elements inside the framelayout are drawn from the upper left corner.
In Absolutelayout, there is no android:layout_margin attribute
The android:layout_alignparentright= "true" property is the child control for the parent container. And the parent container must be relativelayout.
has not understood the difference between android:padding and android:layout_margin, in fact, the concept is very simple, padding is standing in the angle of the parent view to describe the problem, it specifies that its contents must be the distance from the parent view boundary. Margin is to stand in their own perspective to describe the problem, and other (up and down) the distance between the view, if there is only one view at the same level, then its effect is basically the same as 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:BACKGR" Ound= "#FF0000" android:text= "@string/hello" android:paddingleft= "50dip" android:paddingright= "50dip" android:p addingtop= "50dip" android:paddingbottom= "50dip" android:layout_marginbottom= "10dip"/> <textview androi D: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:padd Ingbottom= "50dip" Android:layout_marginbottom= "10dip"/> <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_conte NT "android:background=" #FF0000 "android:text=" @string/hello "android:paddingleft=" 50dip "Android:paddingrigh t= "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:paddingt op= "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:BACKGR" Ound= "#FF0000" android:text= "@string/hello" android:paddingleft= "50dip" android:paddingright= "50dip" android:p addingtop= "50dip" android:paddingbottom= "50dip" android:layout_marginbottom= "10dip"/> <textview androi D: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:padd Ingbottom= "50dip" Android:layout_marginbottom= "10dip"/> <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_conte NT "android:background=" #FF0000 "android:text=" @string/hello "android:paddingleft=" 50dip "Android:paddingrigh t= "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:paddingt op= "50dip" android:paddingbottom= "50dip" android:layout_marginbottom= "10dip"/></linearlayout>
Then I will get the following effect, the figure has been clearly marked out the difference.
The difference between android:padding and Android:layout_margin