LinearLayout: Linear layout
In general, when there are a lot of controls that need to be listed in one interface, we can use linear layout (linearlayout), linear layout is vertical (vertical) or horizontal (horizontal) Order of the child elements, each of which is located after the previous element, let's take a quick look
Some of the following units are encountered in the XML layout file
PX: Is the pixel point of the screen DP: An abstract unit based on density, the physical size of the screen SP: similar to DP, but scaled based on the user's font size
The XML code is as follows: Change the android:orientation= "vertical" vertical direction (vertical)
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical"
tools:context= "Com.example.administrator.adapter.MainActivity" >
<textview
android:text= "First TextView"
Android:background= "#ef0808"
android:gravity= "Center"
Android:textsize= "18SP"
Android:layout_width= "Match_parent"
android:layout_height= "100DP"/>
<textview
Android:text= "A second TextView"
android:gravity= "Center"
Android:background= "#31ef0b"
Android:textsize= "18SP"
Android:layout_width= "Match_parent"
android:layout_height= "100DP"/>
<textview
Android:text= "A third TextView"
android:gravity= "Center"
Android:textsize= "18SP"
Android:background= "#ec07ca"
Android:layout_width= "Match_parent"
android:layout_height= "100DP"/>
<textview
android:text= "Fourth TextView"
android:gravity= "Center"
Android:textsize= "18SP"
Android:background= "#f5d105"
Android:layout_width= "Match_parent"
android:layout_height= "100DP"/>
</LinearLayout>
Running results: Each textview is arranged from top to bottom
The XML code is as follows: Change the android:orientation= "horizontal" horizontal direction (horizontal)
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Horizontal"
tools:context= "Com.example.administrator.adapter.MainActivity" >
<textview
android:text= "First TextView"
Android:background= "#ef0808"
android:gravity= "Center"
Android:textsize= "18SP"
Android:layout_width= "100DP"
android:layout_height= "100DP"/>
<textview
Android:text= "A second TextView"
android:gravity= "Center"
Android:background= "#31ef0b"
Android:textsize= "18SP"
Android:layout_width= "100DP"
android:layout_height= "100DP"/>
<textview
Android:text= "A third TextView"
android:gravity= "Center"
Android:textsize= "18SP"
Android:background= "#ec07ca"
Android:layout_width= "100DP"
android:layout_height= "100DP"/>
<textview
android:text= "Fourth TextView"
android:gravity= "Center"
Android:textsize= "18SP"
Android:background= "#f5d105"
Android:layout_width= "100DP"
android:layout_height= "100DP"/>
</LinearLayout>
Running results: Each textview is arranged horizontally from left to right
The only difference between the two linear layouts is that the value of the android:orientation is different
Experimental summary: The only difference between the two linear layouts is that the value of android:orientation is different, and through this experiment we have a preliminary understanding of the linear layout in Android.
Bigboss bit
LinearLayout Layouts in Android