Five la S and five la s

Source: Internet
Author: User

Five la S and five la s

Linear Layout

LinearLayout is a linear layout control. Its child controls are arranged horizontally or vertically.

Two attributes commonly used by LinearLayout

Android: orientation = "vertical" ---- This attribute determines the layout of its subclass control (vertical: vertical; horizontal: horizontal)

Android: gravity = "center" ---- This attribute determines the position of its subclass xy.

Common attribute values:

Center_vertical: center vertical (Y axis)

Center_horizontal: center horizontally (X axis)

Center: center horizontally and vertically

Right: The subclass control is located on the right of the current layout.

Left: The subclass control is located on the left of the current layout.

Bottom: The subclass control is located under the current layout

Gravity attributes can be used in multiple levels, for example, android: gravity ="Bottom | center"

Attributes commonly used by subclass controls in LinearLayout

Android: layout_gravity = "bottom" ---- indicates the position of XY in the current parent class container.

Android: layout_weight = "1" ---- indicates the proportion of controls in the current parent container.

Relative Layout

RelativeLayout is a relative layout control. Its child controls are arranged in the form of relative positions between controls or the positions of subclass controls relative to parent class containers.

Frame layout FrameLayout

In this layout, all child elements cannot be specified to be placed, they are all placed in the upper left corner of the area, and the child elements behind them directly overwrite the child elements above the area, blocks all parts of the child element.

Absolute Layout

AbsoluteLayout can also be called a coordinate layout. It can directly point to the absolute position (xy) of the stator element)

Mobile phone screen sizes vary greatly

The adaptability to absolute positioning is poor, and there are major defects in screen adaptation.

Attributes of the AbsoluteLayout sub-control

Android: layout_x = "35dp" ---- controls the x position of the control of the current subclass.

Android: layout_y = "40dp" ---- controls the y position of the control of the current subclass.

Table Layout

The TableLayout table layout model manages child controls in the form of columns. Each row is a TableRow object. Of course, it can also be a View object.

TableLayout attributes (Global attributes)

Android: collapseColumns = "1, 2"

Hide index columns starting from 0. Columns must be separated by commas: 1, 2, 5

Android: shrinkColumns = "1, 2"

Shrink index columns starting from 0. If the size of a column that can be shrunk is too large (too much content), the column must be separated by commas (,). You can also use "*" to shrink all columns. Note that a column can both shrink and stretch.

Android: stretchColumns = "1, 2"

Stretch the index column starting from 0 to fill up the remaining blank space. The columns must be separated by commas. You can also use "*" instead of stretching all columns, note that a column can both shrink and stretch.

Local attributes of TableLayout (attributes used by internal controls)

Android: layout_column = "1" ---- the control is displayed in the second column

Android: layout_span = "2" ---- the control occupies two columns.

 


This section describes the five commonly used la s in Android.

Linearlayout linear Layout
Relative layout of Relativelayout
FrameLayout framework Layout
TableLayout table layout
AbsoluteLayout absolute layout (not recommended, the most common is the above four)
 
What are the differences between the five la s in android?

Five layout modes: FrameLayout
Bureau), LinearLayout
(Linear layout), AbsoluteLayout (absolute layout), RelativeLayout (relative layout), TableLayout (table layout)

1. FrameLayout

This layout can be seen as a heap of the wall. There is a wall foot in the upper left corner of the rectangular square. We put the first thing, and we want to put another one, which is placed on the top of the original place, in this way, it will cover the original things. This layout is relatively simple, and you can only put something simple.

2. LinearLayout

Linear layout, which can be understood as a div from the external frame. First, it is listed one by one on the screen. Each LinearLayout can be divided into vertical layout.
(Android: orientation = "vertical") and horizontal layout (android: orientation = "horizontal"
). In vertical layout, each row has only one element, and multiple elements are vertical down in sequence. in horizontal layout, there is only one row, and each element is arranged to the right in sequence.

LinearLayout has an important attribute android: layout_weight = "1". In vertical layout, this weight represents the line spacing; in horizontal layout, it represents the column width; the larger the weight value, the larger the value.

Iii. AbsoluteLayout

The absolute layout is like that div specifies the absolute attribute, and uses the X and Y coordinates to specify the element location. android: layout_x = "20px"
Android: layout_y = "12px" is a simple layout method. However, when you switch between the two elements vertically, problems often occur. In addition, computing is troublesome when multiple elements are involved.

Iv. RelativeLayout

The relative layout can be understood as the layout method for positioning an element as a reference object. Main attributes include:

Relative to an element
Android: layout_below = "@ id/aaa". The element is under aaa.
Android: layout_toLeftOf = "@ id/bbb". The left side of the element is bbb.

Relative to the parent Element

Android: layout_alignParentLeft = "true" align left of the parent Element
Android: layout_alignParentRight = "true" align to the right of the parent Element

You can also specify margins. For details, see API

5. TableLayout

The Table layout is similar to the Table in Html. Each TableLayout contains the table row TableRow, which can define each element and set its alignment mode android: gravity = "".

Each layout has its own method. In addition, these five layout elements can be nested with each other to create a beautiful interface. ----------------- Cvsyun... the remaining full text>

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.