About the content of the margin and padding in XML, there will be some confusion and ambiguity in the first contact with XML, in this summary, hope to help people in need.
2.xml in margin and padding
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:layout_margin= "10DP"//When the margins in the upper and lower left and right four directions are consistent, this unified setting can be used
android:background= "@color/red"
android:orientation= "Vertical" >
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:background= "@color/yellow"
android:layout_marginleft= "5DP"//can be set separately when the margin is inconsistent between the top and left four directions
android:layout_margintop= "15DP"
android:layout_marginright= "25DP"
Android:layout_marginbottom= "35DP"
android:orientation= "Vertical" >
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:layout_margin= "15DP"//This is an outer border
android:padding= "35DP"//This is the inner border, the inner border of the four in the same direction, you can set the unified
android:background= "@color/blue"
android:orientation= "Vertical" >
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:background= "@color/gray"
android:paddingleft= "5DP"//inner border is inconsistent in four directions, can be set separately
android:paddingtop= "15DP"
android:paddingright= "25DP"
Android:paddingbottom= "35DP"
android:orientation= "Vertical" >
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:background= "@color/green"
android:orientation= "Vertical" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
As follows:
The adoption and the settings in the XML should soon be able to grasp the use of margin and padding
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Summary of XML layout content (ii)--android