Today, I studied the layout of Android mainly.
Android layout is generally divided into five types:
LinearLayout (Linear layout): subassemblies are laid out in a vertical or horizontal direction.
Relativelayout (relative layout): The concept of reference is arranged according to the position of the control, there is a layout, there is a concept of a reference (generally in the relative layout of the control will have the ID of the property)
Tablelayout (Table Layout): inherits from the linear layout. (Similar usage)
Absolutelayout (Absolute layout): is positioned by specifying the x/y coordinates of the control (the display is inflexible, is not conducive to development, is almost deprecated).
Framelayout (frame layout): Effect of screen display
First, linear layout
The arrangement direction of a linear layout is manipulated by the Orientaiton property:
Android:orientation = "Vertical" is specified as vertical
Android:orientation = "Horizontal" is specified as horizontal. Default is Horizontal
Layout_weight represents the concept of weights. (i.e. divided by percentage)
Simply look at a chestnut to understand the linear layout.
The results are as follows:
Second, relative layout
1. Relative layout often requires defining the resource ID of each control
Note:
@+id indicates that there is no corresponding ID value in the system, and this ID value needs to be added to the system.
@id: Indicates that an already added ID is removed from the system
Layout_width and Layout_height are an integral part of the two properties in the graphic, and any graphic needs to be displayed with a width and height
Alignbaseline Baseline Alignment
For relative layouts, there are generally no too many associated properties given, otherwise the coupling will be greatly increased
Let's start with 2 layouts today, followed by some properties of our linear layout and relative layout.
A detailed description of linear property layout properties
1 android:layout_gravity The gravity direction of this element relative to the parent element2 3 android:gravity The gravity direction of all child elements of this element4 5 android:orientation Linear Layout displays inner child elements in columns or rows6 7 Android:layout_weight Sub-elements assign weight values horizontally or vertically to unoccupied space8 9 TenWhen 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.!!! One AWhen 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 the difference between android:layout_gravity and android:gravity - -Android:gravity works on the element itself-Where does the element itself appear - +Android:layout_gravity relative to its parent element-element displays where the parent element is located. - + such as: Button control A at 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 values [multiple selection] |[Separate] - in top, bottom, left, right, center_vertical, fill_vertical, Center_horizontal, fill_horizontal, center, fill, Clip_ Vertical - to 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. the * left places the object on its container and does not change its size. $ Panax Notoginseng right places the object on the left side of its container without changing its size. - the center_vertical Centers The object vertically without changing its size. + A Vertical alignment: center-aligned vertically. the + fill_vertical when necessary, increase the vertical size of the object to fully fill its container. Vertical Fill - $ Center_horizontal Center The object horizontally, without changing its size horizontal alignment: Center aligned horizontally $ - fill_horizontal when necessary, increase the horizontal size of the object to fully fill its container. Horizontal Fill - the Center Centers The object horizontally, without changing its size. - Wuyi fill increases the size of the object's longitudinal dimensions as necessary to fully fill its container. the -Clip_vertical additional option to cut the top of the object and/or to follow the edges of the containeror the bottom of the content. 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 the top and bottom are clipped. Crop vertically Wu -Clip_horizontal additional option to cut the left side of the object according to the edges of the container and/or to the right. Clipping is based on its horizontal alignment setting: When aligned to the left, cut to the right, cut to the left when aligned to the right, and cut to the left and right. Crop horizontally About $ Example - -TextView to make text vertical/Horizontal Center Display, there are two situations to consider: - A1, 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". + the2, Layout_width/layout_height is fill_parent, at this time because TextView already occupy the parent form all the space, must set gravity= "center".
View Code
A detailed description of relative layout properties
1 some of the important attributes that Relativelayout uses:2 First Class: property value is True or false3 Android:layout_centerhrizontal Horizontal Center4 android:layout_centervertical Vertical Center5 Android:layout_centerinparent is completely centered relative to the parent element6 Android:layout_alignparentbottom snaps to the bottom edge of the parent element7 Android:layout_alignparentleft snaps to the left edge of the parent element8 Android:layout_alignparentright snaps to the right edge of the parent element9 Android:layout_alignparenttop snaps to the top edge of the parent elementTen android:layout_alignwithparentifmissing if the corresponding sibling element cannot be found, then the parent element is the reference. OneSecond class: The attribute value must be the reference name of the id "@id/id-name " A 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 the 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 A Android:layout_marginleft distance from the left edge of an element at android:layout_marginright distance from the right edge of an element - android:layout_margintop distance from the top edge of an element - EditText's Android:hint - sets the prompt information in the input box when EditText is empty. - android:gravity -The Android:gravity property is the qualification for the view content. For example, a button above the text. You can set the text on the left side of the view, on the right, and so on. Take button for example, android:gravity= "right"the text above the button is on the right in android:layout_gravity -Android:layout_gravity is used to set the location of the view relative to the parent view. For example a button in LinearLayout, you want to put the button on the left, The property can be set by the right-hand position. Take button For example, android:layout_gravity= "right"then button on the right to Android:layout_alignparentright + Aligns the right end of the current control with the right end of the parent control. This property value can only be true or FALSE, which is false by default. - Android:scaletype: theAndroid:scaletype is a size that controls how the picture resized/moved to the ImageView. Imageview.scaletype/the meaning difference of Android:scaletype value: *Center/center is centered on the original size of the image, when the picture is longer/wider than the view's length/width, the center portion of the captured picture is displayed $Center_crop/Centercrop proportionally enlarges the size of the image so that the image is long (wide) equal to or greater than the length (width) of the viewPanax NotoginsengCenter_inside/centerinside Displays the contents of the picture in full, by scaling it down or the original size to make the picture long/wide equal to or less than the length of the View/Wide -Fit_center/fitcenter enlarge the picture proportionallyzoom to view width, center display theFit_end/fitend enlarge the picture proportionallyZoom out to the width of the view, displayed in the lower part of the view +Fit_start/fitstart enlarge the picture proportionallyZoom out to the width of the view, displayed in the upper part of the View AFit_xy/fitxy to enlarge the picture without proportionZoom to view size display theMATRIX/matrix is drawn using matrices to zoom in and out of the image to display. +* * To note that the Drawable folder inside the image name can not be capitalized.
View Code
Android_layout Layout (i)