Detailed introduction to LinearLayout of Android layout control

LinearLayout is a linear layout control. Its child controls will be arranged horizontally or vertically. All widgets or other containers will be arranged according to their relative positions. When they exceed the boundary, some controls will be missing or disappear. Therefore, each row of a vertical list will only have one widget or container, no matter how wide they are, while a horizontal list will only have one row height (the height is the height of the highest child control plus the height of the border). LinearLayout maintains the spacing and alignment between its contained widgets or containers (right alignment, middle alignment or left alignment relative to a control).

API description

XML attribute

Android: baseline aligned: whether to allow users to adjust the baseline of its content.

Android: baselinealignedchildindex: when a linear layout is part of a baseline alignment with another layout, it can specify the baseline alignment of its content.

Android: Gravity: specifies how to place the object's contents (x / Y coordinate values) in the object.

Android: Orientation: set the orientation of its content (horizontal / vertical).

LinearLayout also supports specifying the fill weight for the widget or container it contains. The advantage is that the widget or container it contains can fill the remaining space on the screen. This also avoids the situation that a string of widgets or containers are crowded into a pile in a large screen, but allows them to zoom in and fill in the blank. The remaining space will be allocated to the screen according to the weight ratio specified by these widgets or containers. The default weight value is 0, which means that it is displayed according to the actual size of widgets or containers. If it is higher than 0, the remaining available space of the container will be divided. The division size depends on the layout of each widget or container_ Weight and the proportion of the weight in all widgets or containers. For example, if there are three text boxes, two of which have a specified weight of 1, the two text boxes will be enlarged proportionally and fill the remaining space, while the third text box will not be enlarged and will be displayed according to the actual size. If the values of the first two text boxes are 2 and 1, 2 / 3 of the remaining space after the third text box is displayed is given the weight of 2, and 1 / 3 of the size is given the weight of 1. That is, the greater the weight, the greater the importance.

If the LinearLayout contains child linearlayouts, the greater the weight between the child linearlayouts, the smaller the importance. If LinearLayout a contains LinearLayout C, D, C with a weight of 2 and D with a weight of 1, then 2 / 3 of the screen space is allocated to d with a weight of 1 and 1 / 3 to C with a weight of 2. When the LinearLayout is nested, the weight of the child LinearLayout must be set. Otherwise, by default, the child LinearLayout without the weight occupies the whole screen.

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