"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