Android basics-interface layout (2) linear Layout

Source: Internet
Author: User

Linerlayout is a row (column) that can only place the linear layout of one control. Therefore, when many controls need to be listed, you can use this pull.

Code:

Main. xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >        <TextView         android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:gravity="center_vertical"        android:textSize="15pt"        android:background="#aa0000"        android:layout_weight="1"        android:text="@string/hang1"        />        <TextView         android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:gravity="center_vertical"        android:textSize="15pt"        android:background="#00aa00"        android:layout_weight="1"        android:text="@string/hang2"        />        <TextView         android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:gravity="center_vertical"        android:textSize="15pt"        android:background="#0000aa"        android:layout_weight="1"        android:text="@string/hang3"        />        <TextView         android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:gravity="center_vertical"        android:textSize="15pt"        android:background="#aaaa00"        android:layout_weight="1"        android:text="@string/hang4"        />    </LinearLayout>

Code in string. xml

<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "hello"> Hello world, androidbooklinerlayoutp101activity! </String>
<String name = "app_name"> vertical linear layout </string>
<String name = "hang1"> first line </string>
<String name = "hang2"> Row 2 </string>
<String name = "hang3"> Row 3 </string>
<String name = "hang4"> row 4 </string>
</Resources>

Resolution:

Orientation = "vertical" indicates the vertical linear layout.

Fill_parent indicates that the control fills the screen

Wrap_content indicates that the width or height of the control varies with the text field.

Gravity specifies the location, top, bottom, right, and so on

Layout_weight: The default value is 0, indicating the size of the view to occupy. If the value is greater than 0, it must be separated by the available space of the parent view, the split size depends on the size of the value and the current proportion.

Android: text = "@ string/hang1": reference the hang1 text in string. This is easy to understand. As defined in this way

Android: Background = "# aa0000" background color

Change the vertical above to the Android: Orientation = "horizontal" level, and this effect will appear.

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.