Android Development – five layout details

In HTML, we all know what layout means. In short, it is to divide the page into modules, such as div and table in HTML. So it's the same in Android. The five layouts of Android make the interface more beautiful and easier to develop. Of course, different layout methods are applied in different places. Of course, some layout methods can be converted and nested. They all have their own advantages and disadvantages. The specific page layout depends on the development requirements, but the most used are relative layout, linear layout and the nested use of relative layout and linear layout. Of course, I'm talking about Android. I don't specify Android phones. For example, many tablets and smart homes (TVS...) are Android systems. Now let's specifically talk about the five layouts in Android development. I take a simple dialer as an example.

1、 Android five layout categories

1. Relative layout

2. Absolute layout

3. Linear layout

4. Table layout

5. Frame layout

2、 Use of specific layout

1. Relativelayout

When we create an Android project, the default activity is_ The default layout of the main.xml file is relativelayout relative layout. Then the relative layout is to complete the layout according to the positional relationship between the child elements. The position related attributes in the child elements in this layout will take effect. It can be understood as follows: the parent element in the Android screen is the whole screen, and the child element is those buttons, text boxes and so on.

Relative layout is one of the most commonly used and powerful layouts in Android layout:

1) It can set many properties

2) Can do the most

3) Android screens have different resolutions and sizes, so considering the adaptability of the screen, it is recommended to use relative layout in development.

4) It is easier to locate than elements

a. The following is the XML code for the relative layout

b. Partial label attribute description

c. Effect

2. Absolute layout

Here's an example: we fight landlords with mobile phones. The positions of three players are fixed in three corners, so it's not easy to use relative layout. Then we can easily implement this function with absolute layout.

However, in actual development:

1) This layout format is not normally used

2) Its interface code is too rigid

3) It may not be well adapted to various terminals

So the way of absolute layout has been abandoned by Google's Android development team. Android: layout of child elements in this layout_ X and Android: Layout_ The Y attribute takes effect and describes the coordinate position of the child element. The upper left corner of the screen is the coordinate origin (0,0). The first 0 represents the abscissa, moving to the right increases the value, and the second 0 represents the ordinate, moving down increases the value. Child elements in this layout can overlap each other.

a. The following is the XML implementation code of absolute layout

b. Description of some label attributes:

c. Effect

3. Linear layout

The linear layout is like our mutton kebabs, which are connected by a straight line. Here, it is divided into horizontal and vertical.

The linear layout arranges the child elements in vertical or horizontal order, and each child element is located after the previous element.

1) Vertically arranged, it will be an n-row single column structure, and each row will have only one element, regardless of the width of the element;

2) If it is arranged horizontally, it will be a single row n-column structure.

3) To build a structure of two rows and two columns, the usual way is to arrange two elements vertically, and each element contains a LinearLayout for horizontal arrangement

In other words, vertical and horizontal can be nested with each other, which can achieve the effect of table layout.

a. The following is the XML implementation code of linear layout

b. Partial label attribute description

c. Effect

4. Table layout

We all know a lot about tables, such as Excel tables we often use, and the table tag we use in HTML. In fact, the table layout in Android is similar, so when you need to layout like a table, it is recommended to use table layout

Table layout is suitable for multi row and multi column layout format. A tablelayout consists of many tablerows. A tablerow represents a row in the tablelayout.

1) Tablerow is a subclass of LinearLayout. Ablelayout does not need to explicitly declare how many rows and columns it contains, but controls the number of rows and columns of the table through tablerow and other components,

2) Tablerow is like a tr in a table. It is a container. Therefore, other components can be added to tablerow, that is, the tag attribute. Each component is added to the table, and a column is added to the table. If you want to add a component to tablelayout, the component will directly occupy one row.

3) In the table layout, the width of the column is determined by the widest cell in the column. The width of the whole table layout depends on the width of the parent container. By default, it occupies the parent container itself. The parent container here is equivalent to our whole screen.

a. The following is the XML implementation code of table layout

b. Partial label attribute description

Tablerow: rows

c. Effect

5. Frame layout (frame layout)

Frame layout is also called frame layout in some places. It is the simplest layout form, so it is rarely used in actual development. All views added to this layout are displayed in a cascading manner. The first added control is placed at the bottom, the last view added to the frame layout is displayed at the top, and the control of the upper layer will overwrite the control of the next layer. This display is somewhat similar to a stack.

a. The following is the implementation code of frame layout XML

b. Partial label description

It is found that there is no label to explain here ~ ~ hahaha, then I think it has been omitted

c. Effect

3、 Summary

1. In actual development, each layout does not exist independently, but can be nested with each other, just like div nested tables in HTML, and then tables nested Div

2. Which layout to use depends on what layout a page needs to use to realize it more conveniently and quickly, and to maintain it more conveniently

3. Although the absolute layout has been abandoned, it is still possible to use it in specific development. We just need to understand it

4. The layout is not only convenient and convenient for maintenance, but also brings better page beauty

5. Some layouts and layouts can be replaced, such as relative layout, linear layout and table layout

6. There are many layout properties. Maybe smart people can see the rules. Are you familiar with the CSS we learned? You can learn it yourself

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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
分享
二维码
< <上一篇
下一篇>>