LinearLayout for Android Application Development (linear layout)

Source: Internet
Author: User

 

"LinearLayout" is translated into Chinese as "linear layout ", the linear layout means that all the sub-elements under the label are displayed one by row or one by column based on the value of the orientation attribute.

The main. xml layout file is as follows:

 

<? Xml version = "1.0" encoding = "UTF-8"?>

<LinearLayout

Xmlns: android "http://schemas.android.com/apk/res/android"

Android: orientation = "vertical"

Android: layout_width = "fill_parent"

Android: layout_height = "fill_parent"

>

<TextView

Android: layout_width = "fill_parent"

Android: layout_height = "wrap_content"

Android: text = "@ string/name_text"

/>

<EditText

Android: layout_width = "fill_parent"

Android: layout_height = "wrap_content"/>

<Button

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: text = "@ string/cancle_button"

/>

<Button

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: text = "@ string/OK _button"/>

</LinearLayout>

The content of strings. xml is as follows:

 

<? Xml version = "1.0" encoding = "UTF-8"?>

<Resources>

<String name = "hello"> Hello World, UIActivity! </String>

<String name = "app_name"> User Interface </string>

<String name = "name_text"> enter the user name </string>

<String name = "OK _button"> OK </string>

<String name = "cancle_button"> cancel </string>

</Resources>

After running, such:

 

"Xmlns: android" specifies the namespace. The namespace must be specified for top-level elements. The property of the control in the namespace, such as layout_width, must be prefixed with "android:" Before the property.

"Layout_width" specifies the width of the element. There are three optional values: "fill_parent", "wrap_content", and specific numbers (unit: px ). "Fill_parent" indicates filling up the parent element. for top-level elements, the parent element is the entire mobile phone screen. "Wrap_content" indicates that the size of the element only wraps its own content, while the number indicates that it occupies the corresponding px.

"Layout_height" specifies the height of the element. The optional parameter value is the same as that of "layout_width.

"Orientation" refers to the arrangement of sub-elements. If it is specified as "vertical", the sub-elements are vertically arranged. Each sub-element occupies an independent row, as shown in, another optional value, horizontal, indicates horizontal arrangement of child elements, that is, each child element occupies an independent column. The following is an example of the main. xml layout file. The corresponding

The content of strings. xml remains unchanged.

 

Main. xml

<? Xml version = "1.0" encoding = "UTF-8"?>

<LinearLayout

Xmlns: android = "http://schemas.android.com/apk/res/android"

Android: orientation = "horizontal"

Android: layout_width = "fill_parent"

Android: layout_height = "fill_parent"

>

<TextView

Android: layout_width = "wrap_content"

Android: layout_height = "fill_parent"

Android: text = "@ string/name_text"

/>

<EditText

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"/>

<Button

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: text = "@ string/cancle_button"

/>

<Button

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: text = "@ string/OK _button"/>

</LinearLayout>

After running, such:

 

Excerpted from the column

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.