LinearLayout: Linear layout
LinearLayout is a linear layout control that contains child controls that are arranged in a horizontal or vertical manner.
When all widgets or other containers are arranged in a relative position, some controls will be missing or disappear when the boundary is exceeded.
So each line of a vertical list will have only one widget or container, no matter how wide they are,
A horizontal list will have only one row high (height is the height of the highest child control plus the border height).
The linearlayout maintains the spacing between the widgets it contains or the container and aligns with each other (right-aligned, Middle-aligned, or left-aligned relative to a control).
LinearLayout attribute Details:
Android:layout_gravity the gravity direction of this element relative to the parent element
Android:gravity the gravity direction of all child elements of this element
Android:orientation Linear layout Displays inner child elements in columns or rows
Android:layout_weight Sub-elements assign weight values horizontally or vertically to unoccupied space
When android:orientation= "vertical", only the horizontal setting will work, and the vertical setting will not work. That is: The left,right,center_horizontal is in force.
When android:orientation= "Horizontal", only the vertical setting will work, and the horizontal setting will not work. That is: The top,bottom,center_vertical is in force.
The difference between android:layout_gravity and android:gravity
Android:gravity works on the element itself-where the element itself is displayed
Android:layout_gravity relative to its parent element-where the element is displayed in the parent element.
such as: Button control
Android:layout_gravity indicates the position of the button on the interface
The android:gravity represents the position of the word on the button on the button.
Optional value [multi-select with ' | ' Separate
Top, bottom, left, right, center_vertical, fill_vertical, Center_horizontal, fill_horizontal, center, fill, Clip_ Vertical
Top places the object at the top of its container without changing its size.
Bottom places the object at the bottom of its container without changing its size.
Left places the object on its container and does not change its size.
Right places the object on the left side of its container without changing its size.
Center_vertical centers the object vertically without changing its size.
Vertical alignment: Center-aligned vertically.
fill_vertical increase the vertical size of the object to fully fill its container when necessary. Vertical fill
Center_horizontal Center The object horizontally, without changing its size horizontal alignment: Center aligned horizontally
Fill_horizontal increase the horizontal size of the object to fully fill its container when necessary. Fill horizontally
Center centers the object horizontally, without changing its size.
Fill increases the size of the object's longitudinal dimensions as necessary to fully fill its container.
Clip_vertical additional option to cut the contents of the top and/or bottom of the object according to the edges of the container. Clipping is based on its vertical alignment settings: When the top is aligned, the bottom is clipped, the top is clipped at the bottom, and in addition to the top and bottom of the cut. Crop vertically
Clip_horizontal additional option to cut the contents of the left and/or right of the object according to the edges of the container. Clipping is based on its horizontal alignment settings: Cut to the right when aligned to the left, cut to the left when aligned to the right, and cut to the left and right. Crop horizontally
Example
TextView to allow text to be centered vertically/horizontally, there are two things to consider:
1, Layout_width/layout_height is wrap_content, at this time to let TextView on the parent control on the center display, you must set the layout_gravity= "center."
2, Layout_width/layout_height is fill_parent, at this time because TextView already occupy the parent form all the space, must set gravity= "center".
Realtivelayout: Relative layout
* Often need to define the resource ID of each control
* The view components in the relative layout are determined by the relative position of each other.
* Arrange according to the position of the control. There is a concept of reference
* @+id: Indicates that the corresponding ID value does not exist in the system, and this ID value needs to be added to the system.
* @id: Indicates that an already added ID has been removed from the system.
* Alignbaseline: Baseline alignment
* For relative layouts, there are generally not too many associated properties given. Otherwise, the coupling will be greatly increased.
Some of the important attributes that relativelayout uses:
First Class: Property value is True or False
Android:layout_centerhrizontal Horizontal Center
Android:layout_centervertical Vertical Center
Android:layout_centerinparent is completely centered relative to the parent element
Android:layout_alignparentbottom snaps to the bottom edge of the parent element
Android:layout_alignparentleft snaps to the left edge of the parent element
Android:layout_alignparentright snaps to the right edge of the parent element
Android:layout_alignparenttop snaps to the top edge of the parent element
android:layout_alignwithparentifmissing if the corresponding sibling element cannot be found, then the parent element is the reference.
Second class: The attribute value must be the reference name of the id "@id/id-name"
Android:layout_below at the bottom of an element
Android:layout_above at the top of an element
Android:layout_toleftof on the left side of an element
Android:layout_torightof on the right side of an element
Android:layout_aligntop aligns the top edge of this element with the top edge of an element
Android:layout_alignleft aligns the left edge of this element with the left edge of an element
Android:layout_alignbottom aligns the bottom edge of this element with the bottom edge of an element
Android:layout_alignright aligns the right edge of this element with the right edge of an element
Class III: Attribute values are specific pixel values, such as 30dip,40px
Android:layout_marginbottom distance from the bottom edge of an element
Android:layout_marginleft distance from the left edge of an element
Android:layout_marginright distance from the right edge of an element
Android:layout_margintop distance from the top edge of an element
Android ch06 layout layouts (i)