Android basic learning layout and android basic layout
The first step I learned about android is layout learning. Layout is the foundation of androidUI and the top priority. In general, android has six layout S: LinearLayout, RelativeLayout, FrameLayout, AbsoluteLayaout, TableLayout, and GridLayout. I think the first three types of layout are most commonly used in the development process. The following describes the attributes of the first three la S.
Linear layout LinearLayout:
Android: orientation:Horizontal, vertical)
Vertical linear layout: only one control can be placed on each row, and the row will be squeezed out if it cannot be placed at the bottom,
Horizontal linear layout: each column can have only one control, and the control can be squeezed out if it cannot be placed on the right.
If this attribute is not set, the default value is horizontal.
Control width and height:
Attribute: match_parent/fill_parent fill parent form (fill_parent has been deprecated)
Wrap_content Package content
Absolute Number, for example, 150dp
Background: Set the background color:
Number of digits: 3/4 6/8 ARGB (alpha (transparency) red green blue)
#00 ffffff completely transparent
# Ffffffff is completely opaque
#88 ffffff translucent
# Fff white ffffff
#000 black
# F00 red
#0f0 green
# 00f blue
# Ccc gray 333 666 999
Attribute:
Android: layout_gravity(Internal and external requests) used to align controls with outer containers
Value Options: top, bottom, left (start), right (end), center_vertical, center_horizontal, and center.
Note: In the vertical linear layout, top, bottom, and center_vertical are invalid. The center is invalid in the vertical direction.
In the horizontal linear layout, left (start), right (end), and center_horizontal are invalid, and center is invalid in the horizontal direction.
Android: gravityThe position of the container contents in the control view does not conflict with its own horizontal and vertical attributes.
Value Options: top, bottom, left (start), right (end), center_vertical, center_horizontal, and center.
Layout_gravity: defines the control position.
Gravity: defines the position of the content in the control. If it is defined in the layout, the overall control is placed according to its defined position.
Weight:Android: layout_weight is an attribute used to allocate the remaining space,
Note:
Set the weight in the horizontal direction: Set the width to 0dp,
Set the height to 0dp when setting the weight in the vertical direction.
If wrap_content is set, the weight will be affected.
Relative layout RelativeLayout:
Attributes are mainly divided into four categories
1. Seven attributes relative to the parent element:
Align the control with the top of the parent element: android: layout_alignParentTop
Align the control with the bottom of the parent element: android: layout_alignParentBottom
Align the control with the left of the parent element: android: layout_alignParentLeft
Align the control to the right of the parent element: android: layout_alignParentRight
Center all: centerInParent
Horizontal center: layout_centerHorizontal
Vertical center: layout_centerVertical
2. Compared with four sibling elements
Layout_abve; specifies the upper side of the control.
Layout_below specifies the lower side of the control
Android: layout_toLeftOf layout_toStartOf is specified on the left side of the control. We recommend that you use this function in api Version 17.
Android: layout_toRightOf layout_toEndOf is specified on the right side of the control. We recommend that you use this function in api Version 17.
3. Alignment with respect to sibling Elements
Layout_alignLeft the left side of the control is aligned with the left side of the control
Layout_alignRight: the right side of the control is aligned with the right side of the control
Layout_alignTop the upper edge of the control is aligned with the upper edge of the specified control
Layout_alignBottom: the lower edge of the control is aligned with the lower edge of the specified control.
4. Interval
PaddingXXX padding (no direction specified, four sides available)
Layout_marginXXX margin (no direction specified, all around)
Frame layout FrameLayout:
Frame layout is mainly used for fragment's main layout.
The above is the layout learning content. I think the difficulty lies in the linear layout.Layout_gravity andGravity