LinearLayout Layouts in Android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.