android:layout

Introduction to the layout:
1. There are five layouts in versions before 4.0, all of which are subclasses of ViewGroup. They are AbsoluteLayout, RelativeLayout, LinearLayout, FrameLayout, TableLayout. And TableLayout is a subclass of LinearLayout. (Chinese are: absolute layout, relative layout, linear layout, frame layout, table layout).
2. AbsoluteLayout expired in 2.2 operating system. At present, TableLayout is gradually used less and less.
3. GridLayout was added after 4.0. (The most classic case of GridLayout is the calculator interface)
In short, there are six layouts in Android. Currently, it is recommended to use RelativeLayout, LinearLayout, and GridLayout.

LinearLayout:
(1) Concept: Linear layout controls the horizontal or vertical arrangement of controls or components in it. In a non-linear layout layout, only one control can be placed in each row or column. And linear layout doesn't wrap. When the controls are arranged to the edge of the form, the following controls are hidden and not displayed.
The default orientation of Linear Layout is Horizontal. vertical

(2) Common properties of LinearLayout:
1.android:orientation defines the arrangement of controls or components within the layout
Options: vertical , horizontal

2.android:layout_width defines the width of the control
Optional: fill_parent / match_parent / wrap_content / absolute value
Remarks: The effect of fill_parent / match_parent is exactly the same, both filling the entire parent control. But match_parent is recommended since version 2.2. wrap_content means that the width of the control just wraps the content.

3.android:layout_height defines the height of the control
Optional: fill_parent / match_parent / wrap_content / absolute value
Remarks: The effect of fill_parent / match_parent is exactly the same, which is to fill the entire parent control with a height. wrap_content means that the height of the control just wraps the content.

4.android:id Set the id of the control. In this way, the corresponding value can be automatically generated in R.java, which can be called by findViewById in the program.
The format of setting the id is: android:id = "@+id/id's name"

5.android:background Set the background color or background image of the control
For example: android:background="#ffffff"
          android:background="@drawable/image name"
【Remark:】
Colors are available in RGB color format and ARGB format. RGB is the three primary colors of red, green and blue. ARGB is the three primary colors with alpha, that is, the three primary colors with transparency.
#FFFFFF stands for white
#000000 black
#FFFFFFFF fully opaque
#00FFFFFF fully transparent
#88FFFFFF Translucent

6.android:layout_weight Set the weight of the control. That is, each control is evenly distributed in the horizontal or vertical direction.
Note: If the weight is set in the horizontal direction, set android:layout_width to 0dp; if the weight is used in the vertical direction, set android:layout_height to 0dp. Otherwise, the weights are easily biased by the interference of height or width.

7.android:gravity This attribute is used to control the position of the contents of the View.
If this property is defined in a layout node, the positions of all controls in the layout are controlled by this property.
If this property appears in controls such as Button, TextView, EditText, etc., it is used to control the position of the text on these controls.
The options are: top, bottom, left, right, center_vertical, fill_vertical, center, fill, etc.
[Remarks:] This attribute is different from android:layout_gravity.

8.android:layout_gravity This attribute is used to set the alignment of the control relative to the container.
The options are: top, bottom, left, right, center_vertical, center_horizontal, fill_vertical, center, fill, etc.
These options are not available for every layout. In vertical linear layout, android:gravity is bottom does not work; and in horizontal linear layout, android:gravity is right does not work.
[Note:] This attribute is the android:layout_gravity attribute, which is different from the android:gravity attribute.
(3), LinearLayout's unique attributes: [Re-induction: unique attributes after removing public attributes]
1. The arrangement of components in the android:orientation layout manager
2. android:gravity sets the alignment of components in the layout manager
(4), the unique attributes of LinearLayout child elements:
1. The weight of android:layout_weight child elements in LinearLayout
2. Alignment of android:layout_gravity child elements in LinearLayout

RelativeLayout:
(1) Concept: It refers to the layout according to the relative position between the controls.
(2), RelativeLayout-specific attributes:
1. android:gravity sets the alignment of the child controls in the layout container    
2. android:ignoreGravity sets which controls in the layout manager are not affected by the gravity attribute
(3), Unique attributes of RelativeLayout child elements: LayoutParams
    A. Group 1: Refers to the relative position between sibling controls. The value of the group property is the id of another control.
layout_toRightOf which control is to the right of the control
layout_toLeftOf which control is to the left of the control
layout_above which control the control is on
layout_below under which control the control is located
    B. The second group: refers to the alignment relationship between sibling controls. The value of the group property is the id of another control.
layout_alignRight the right alignment of the control to which control
layout_alignLeft to which control the control is aligned to the left
layout_alignTop to which control the top of the control is aligned
layout_alignBottom which control is aligned to the bottom of the control
    C. The third group: refers to the alignment relationship between the control and the parent layout. The value of this set of properties is true or false.
layout_alignParentRight Is the control aligned to the right of the parent layout control?
layout_alignParentLeft Is the control aligned to the left of the parent layout control?
layout_alignParentTop Is the control aligned to the top of the parent layout control?
layout_alignParentBottom Is the control aligned to the bottom of the parent layout control?
layout_centerInParent Is the control in the center of the parent layout control?
layout_centerVertical Is the control in the vertical center of the parent layout control?
layout_centerHorizontal Is the control in the horizontal center of the parent layout control?

GridLayout: grid layout
(1), GridLayout layout properties:
1、android:alignmentMode
Property Description: Set the alignment mode of the layout. Can take the following values:
alignBounds -- Align subview bounds.
alignMargins -- aligns the subview margins.
2、android:columnCount
Property description: The maximum number of columns of GridLayout
3、android:rowCount
Property description: The maximum number of rows of GridLayout
4、android:orientation
Property description: The layout direction of child elements in GridLayout. Has the following values:
horizontal -- horizontal layout.
vertical -- vertical layout.
5、android:columnOrderPreserved
Property description: Set whether the grid layout retains the column number. Default is true.
6、android:rowOrderPreserved
Property description: Set whether the grid layout preserves row numbers. Default is true.
7、android:useDefaultMargins
Property Description: Set the GridLayout to use the default margins. The default value is false.
(2) Attributes of GridLayout child elements:
1、android:layout_column
Property Description: Displays the control's columns. For example, android:layout_column="0" indicates that the control is displayed in the first column; android:layout_column="1" indicates that the control is displayed in the second column.
2、android:layout_row
Property Description: The row where the control is located. For example, android:layout_row="0" indicates that the control is displayed in the first row; android:layout_row="1" indicates that the control is displayed in the second row. It is similar to android:layout_column.
3、android:layout_columnSpan
Property description: Column merge. That is, the number of columns occupied by the control. For example, android:layout_columnSpan="2" means that the control occupies 2 columns.
 
4、android:layout_rowSpan
Property description: Line merge. That is, the number of rows occupied by the control. For example, android:layout_rowSpan="2" means that the control occupies 2 rows.
5、android:layout_gravity
Property Description: The layout of the control. Option value:
top -- the control is placed on top of the container, without changing the size of the control.
bottom -- the control is placed at the bottom of the container and does not change the size of the control.
left -- The control is placed on the left side of the container, without changing the size of the control.
right -- the control is placed on the right side of the container, without changing the size of the control.
center_vertical -- The control is placed in the vertical center of the container, without changing the size of the control.
fill_vertical -- Extend the control vertically if needed.
center_horizontal -- The control is placed in the horizontal center of the container, without changing the size of the control.
fill_horizontal -- Extend this control horizontally if needed.
center -- The control is placed in the center of the container, without changing the size of the control.
fill -- Extend the control horizontally and vertically if needed.
clip_vertical -- vertical clipping, the direction of clipping is based on the control's top/bottom layout properties. If the control's gravity is vertical: if its gravity is top, the bottom of the control is cut; if the control's gravity is bottom, the top of the control is cut.
clip_horizontal -- horizontal clipping, the direction of clipping is based on the control's left/right layout properties. If the control's gravity is horizontal: if its gravity is left, the right side of the control is cut; if the control's gravity is right, the left side of the control is cut.
start -- the control is placed at the beginning of the container and does not change the size of the control.
end -- the control is placed at the end of the container, without changing the size of the control.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326988941&siteId=291194637