AndroidLayoutLinearlayout(Linear layout)
Linear layout is relatively simple and easy to understand. Let's take a look at the following code:
XML layout File
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent"> <br/> <linearlayout <br/> Android: Orientation = "horizontal" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: layout_weight = "1"> <br/> <textview <br/> Android: TEXT = "red" <br/> Android: gravity = "center_horizontal" <br/> Android: Background = "# aa0000" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "fill_parent" <br/> Android: layout_weight = "1"/> <br/> <textview <br/> Android: text = "green" <br/> Android: gravity = "center_horizontal" <br/> Android: Background = "#00aa00" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "fill_parent" <br/> Android: layout_weight = "1"/> <br/> <textview <br/> Android: TEXT = "blue" <br/> Android: gravity = "center_horizontal" <br/> Android: Background = "# tianaa" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "fill_parent" <br/> Android: layout_weight = "1"/> <br/> <textview <br/> Android: text = "yellow" <br/> Android: gravity = "center_horizontal" <br/> Android: Background = "# aaaa00" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "fill_parent" <br/> Android: layout_weight = "1"/> <br/> </linearlayout> </P> <p> <linearlayout <br/> Android: orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: layout_weight = "1"> <br/> <textview <br/> Android: text = "row one" <br/> Android: textsize = "15pt" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_weight = "1"/> <br/> <textview <br/> Android: text = "row two" <br/> Android: textsize = "15pt" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_weight = "1"/> <br/> <textview <br/> Android: text = "Row Three" <br/> Android: textsize = "15pt" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_weight = "1"/> <br/> <textview <br/> Android: text = "row four" <br/> Android: textsize = "15pt" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_weight = "1"/> <br/> </linearlayout>
It is as follows:
This example is from the official document. The following describes the layout:
Android: Orientation = "vertical"
It determines the direction of linearlayout, and its value can be
* Vertical, indicating the vertical layout
* Horizontal, indicating horizontal layout
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
Specify the width and height of the current control in the parent control respectively. You can set the value, but the following two values are generally used.
* Fill_parent: fills the blank space of the parent control.
* Wrap_content indicates that the size is enough to display the content in the current control.
Android: gravity = "center_horizontal"
If this attribute is set for a view without a child control, it indicates the alignment of the content. If this attribute is set for a view with a child control, it indicates the alignment of the Child control (gravity tendency ), the value is as follows (Separate multiple values with "|)
* Top
* Bottom
* Left
* Right
* Center_vertical
* Center_horizontal
* Center
* Fill_vertical
* Fill_horizontal
* Fill
You don't need to explain it in detail. You can see what it means by literal meaning.
Finally, we will give a slightly complex linearlayout layout code. If you are interested, please try it.
<Br/> <? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> <linearlayout <br/> Android: orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_weight = "1"> <br/> <textview <br/> Android: text = "red" <br/> Android: gravity = "fill_vertical" <br/> Android: background = "# aa0000" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_weight = "1"/> <br/> <textview <br/> Android: text = "white" <br/> Android: textcolor = "# ff0000" <br/> Android: Background = "# ffffff" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_weight = "1"/> <br/> </linearlayout> </P> <p> <linearlayout <br/> Android: orientation = "horizontal" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_weight = "1" <br/> <linearlayout <br/> Android: Orientation = "horizontal" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "fill_parent" <br/> Android: layout_weight = "1"> <br/> <textview <br/> Android: TEXT = "green" <br/> Android: textcolor = "# ff0000" <br/> Android: Background = "#00aa00" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "fill_parent" <br/> Android: layout_weight = "1"/> <br/> <textview <br/> Android: text = "blue" <br/> Android: background = "# javasaa" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "fill_parent" <br/> Android: layout_weight = "1"/> <br/> </linearlayout> </P> <p> <linearlayout <br/> Android: orientation = "vertical" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "fill_parent" <br/> Android: layout_weight = "1"> <br/> <textview <br/> Android: text = "black" <br/> Android: background = "#000000" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_weight = "1"/> <br/> <textview <br/> Android: text = "yellow" <br/> Android: background = "# aaaa00" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_weight = "1"/> <br/> <textview <br/> Android: text = "unkown" <br/> Android: background = "#00 aaaa" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: layout_weight = "1"/> <br/> </linearlayout> </P> <p> </linearlayout> <br/> </linearlayout>
: