Detailed explanation of five layout modes of Android

The five layout methods commonly used in Android are as follows:

Linear layout: components laid out vertically or horizontally. FrameLayout: layout components from the top left of the screen. Table layout: layout components in rows and columns. Relative layout: the layout method relative to other components. Absolute layout: layout components in absolute coordinates.

1. Linear layout

Linear layout is the most common layout method in Android development. It is arranged according to the vertical or horizontal direction. The direction of linear layout can be set through the "Android: orientation" attribute. Attribute values are vertical and horizontal.

Common attributes:

Android: Orientation: you can set the orientation of the layout. Android: Gravity: it is used to control the alignment of components. Layout_ Weight: controls the relative size of each component in the layout

First instance

① Renderings:

② The core code is as follows:

Second instance

① Renderings:

② Core code:

2. Frame layout

Frame layout starts from the upper left corner (0,0) coordinates of the screen. Multiple components are arranged in layers. The first added component is placed at the bottom, and the view added to the frame is displayed at the top. The control of the previous layer will overwrite the control of the next layer.

Simple example

① Renderings:

② Core code:

3. Table layout

A table layout is a ViewGroup that displays its sub view elements in a table, that is, rows and columns, identifying the location of a view.

Common attributes of table layout are as follows:

Android: columnsecolumns: hide the specified column Android: shrinkcolumns: shrink the specified column to fit the screen without extruding the screen Android: stretchcolumns: try to fill the blank part of the specified column Android: Layout_ Column: the control is placed in the specified column Android: layout_ Span: the number of columns the control spans

Simple columns:

① Renderings:

② Core code:

4. Relative layout

Relative layout is based on the relative position between components, such as the left, right, top and bottom of a component.

For common properties of relative layout, please refer to my blog: https://www.oudahe.com/p/28123/

Simple example

① Renderings:

② Core code:

5. Absolute layout

Absolute layout determines the location of components by specifying the exact X and Y coordinates of sub components. In Android 2 The 0 API document indicates that this class has expired. You can use FrameLayout or relativelayout instead. So I won't introduce it in detail here.

The above is the data sorting of the five layouts of Android. We will continue to supplement relevant data in the future. Thank you for your support for this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>