Detailed layout of Android absolutelayout and relativelayout

Android linear layout: absolutelayout layout and relativelayout layout.

1. Absolute layout absolutelayout

Absolute positioning absolutelayout, also known as coordinate layout, can directly specify the absolute position of child elements. This layout is simple, direct and intuitive. However, due to the large difference of mobile phone screen size, the adaptability of using absolute positioning will be poor.

Let's take an example: the size of the robot image in the example is 250x250. You can see that we use Android: layout_ X and Android: Layout_ Y to specify the vertical and horizontal coordinates of the child elements.

Let's take a look at the display effect under the wqvga simulator:

Then check the display effect under the wvga800 simulator:

Tip: in absolute positioning, if the child element does not set layout_ X and layout_ y. Then their default value is 0, which means that it will appear in the upper left corner as in FrameLayout.

2. Relative layout

Relative layout relativelayout allows child elements to specify their position relative to their parent or sibling elements, which is one of the most commonly used layout methods in actual layout. It is much more flexible. Of course, there are many attributes, the operation is difficult, and the possibility of conflict between attributes is also large. When using relative layout, more tests should be done.

Let's do the above example again with relative layout. First, place a picture, and the other two texts are positioned relative to the previous element:

Let's take a look at the display effect under the wqvga simulator:

Take another look at the display effect on the larger screen (wvga800) simulator:

It can be seen from the above figure that the interface effect is basically consistent, rather than shrinking in the upper left corner like absolute positioning; Students see that the function of automatic scaling is the benefit of using dip as unit. About dip, students who don't understand can read the special articles I wrote in the development of small knowledge.

Here are some important attributes used in relativelayout:

The first type: the attribute value is true or false

Type 2: the attribute value must be the reference name "@ ID / ID name" of ID

Category III: attribute values are specific pixel values, such as 30dip and 40px

Let's do the above example again. This time, put more attributes in it. Let's experiment:

The above is the introduction of Android absolute layout and relativelayout layout. We will continue to sort out relevant materials 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
分享
二维码
< <上一篇
下一篇>>