The first thing to understand is that the Android component uses a box model, with the same margin and padding attributes as the HTML tag, but with a different name. Second, Android does not use the PX unit in the layout, but uses the DP as the length unit, the SP is the font size unit
First, linear layout linealayout
It is important to note that the linearlayout tag has a required attribute android:orientation, which indicates whether the component is horizontally expanded (horizontal) or vertically expanded (vertical). Here is a basic use of a linearlayout
1. Horizontal Expansion--horizontal
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Horizontal"><!--Horizontal Expansion - <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_margin= "10DP"Android:background= "@color/coloraccent"Android:text= "This is Text 1!"android:textsize= "25SP"/> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_margin= "10DP"Android:background= "@color/colorprimary"Android:text= "This is Text 2"android:textsize= "20SP"/></LinearLayout>
Preview: You can see the second textview on the right of the first TextView
2. Expand--vertical Vertically
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"><!--verticalExpand - <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_margin= "10DP"Android:background= "@color/coloraccent"Android:text= "This is Text 1!"android:textsize= "25SP"/> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_margin= "10DP"Android:background= "@color/colorprimary"Android:text= "This is Text 2"android:textsize= "20SP"/></LinearLayout>
Preview: You can see the second TextView below the first TextView
Two
Android Project three layouts