The five main layouts of Android development

Source: Internet
Author: User

One, the 5 commonly used in Android layout method has the following several:

Linear layout (LinearLayout): Components that are laid out in a vertical or horizontal direction.

Relative layout (relativelayout): How to lay out relative to other components.

Absolute Layout (absolutelayout): The component is laid out in absolute coordinates.

Table layout (tablelayout): Layout components by row and column.

Frame layout (framelayout): Components from the top left of the screen layout component.

Second, the layout:

1. linear layout: The linear layout is arranged in a vertical or horizontal direction, and the direction of the linear layout can be set by the "Android:orientation" property. There aretwo types of property values: Vertical (vertical) and horizontal (horizontal).

Common Properties:

Android:orientation: You can set the orientation of the layout to be displayed in columns or rows.
Android:gravity: Used to control the alignment of a component relative to the gravity direction of the parent element.
Layout_weight: Controls the relative size of each component in the layout, assigning weight values horizontally or vertically to unoccupied space.

Related knowledge:

android:layout_gravity This element is relative to the gravity direction of the parent element android:gravity the gravity direction of all child elements of this element android:orientation linear layout displays internal child elements in columns or rows Android : Layout_weight Sub-elements assign weights horizontally or vertically to unoccupied space worth 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 the element itself-Where the element itself is displayed android:layout_gravity relative to its parent element-element displays where the parent element is located. For example, the button control android:layout_gravity represents the position of the button on the interface android:gravity represents the position of the word on the button on the button. Optional values [multi-select time use]|"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. Fill vertically center_horizontal the object horizontally, without changing its size horizontal alignment: Horizontally aligned fill_horizontal when necessary increase the horizontal size of the object to fully fill its container. The Horizontal Fill 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 top of the object and the edges of the container according to the/or 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. Vertical cropping clip_horizontal additional options for cutting the left and right of the object according to the edges of the container/or to the right. Clipping is based on its horizontal alignment setting: 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. Horizontal clipping example TextView to make the text vertical/Horizontal Center Display, there are two situations 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".

2, relative layout: relative layout is based on the relative position between components to layout, such as on the left side of a component, right, above and below.

Some of the important attributes that Relativelayout uses:

some of the important attributes that Relativelayout uses: the first Class: The property value is True or false android:layout_centerhrizontal is centered horizontally android:layout_centervertical Center vertically android:layout_centerinparent The Android:layout_alignparentbottom the bottom edge of the parent element relative to the parent element in the full center 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 used as a reference. The second class: The attribute value must be the referenced name of the ID "@id/id-The name "Android:layout_below" at the bottom of an element android:layout_above above an element android:layout_toleftof on the left side of an element android:layout_t Orightof to the right of an element android:layout_aligntop the top edge of this element and the top edge of an element align Android:layout_alignleft the left edge of this element and the left edge of an element to Android:  Layout_alignbottom the bottom edge of this element and the bottom edge of an element are aligned android:layout_alignright the right edge of this element and the right edge of an element are aligned with the third class: The attribute value is a specific pixel value, such as 30dip,40px  Android:layout_marginbottom distance from the bottom edge of an element android:layout_marginleft the distance from the left edge of an element android:layout_marginright the right edge of an element  Android:layout_margintop the distance from the top edge of an element edittext the Android:hint setting EditText is empty when the message is in the input box. The Android:gravity android:gravity property is the qualification of 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 on the button above the right android:layout_gravity android:layout_gravity is used to set the position of the view relative to the parent view. Like a button in LinearLayout, You can set the button on the left, right, and so on. Take button for example, Android:layout_gravity= "Right"The button on the right 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:android:scaleType is how to control the picture resized/moved to the size of ImageView. Imageview.scaletype/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 view Center_inside/Centerinside The contents of the picture to the full center, by scaling it down or the original size so that the picture length/width is equal to or less than the length of the View/wide Fit_center/Fitcenter Enlarge the picture proportionally/zoom to view width, center display fit_end/fitend Enlarge the picture proportionally/Zoom out to the width of the view, displayed in the lower part of the view Fit_start/Fitstart Enlarge the picture proportionally/zooms out to the width of the view, displayed in the upper part of the View Fit_xy/fitxy enlarge the picture without proportionZoom to view size display MATRIX/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.

3. Table layout : A table layout is a viewgroup that displays its child view elements in a table, where rows and columns identify the location of a view.

Common properties are as follows: Android:collapsecolumns: Hide the specified column
Android:shrinkcolumns: Shrinks the specified column to fit the screen and does not extrude the screen
Android:stretchcolumns: Try to fill the specified column with blank parts
Android:layout_column: The control is placed in the specified column
Android:layout_span: The number of columns that the control spans 4,Absolute Layout:Absolute layout determines the position of the component by specifying the exact x, y coordinates of the subassembly. (Note: You can use Framelayout or relativelayout instead) the commonly used properties are as follows: android:layout_x= "40px" Android:la Yout_y= "40px" 5,Frame layout:The frame layout starts from the upper left corner (0,0) coordinates of the screen, multiple components are stacked, the first added component is placed at the bottom, and the last view added to the frame is displayed at the top.           The previous layer overrides the next layer of control. The common properties are as follows:

Android:foreground: Sets the foreground image of the frame layout container

Android:foregroundgravity: Setting the location of the foreground image display

<?xml version= "1.0" encoding= "Utf-8"? ><framelayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" > <TextView android:layout_width= "300DP"Android:layout_height= "300DP"Android:background= "#00BFFF"//Blue/> <TextView android:layout_width= "260DP"Android:layout_height= "260DP"Android:background= "#FFC0CB"//Powder/> <TextView android:layout_width= "220DP"Android:layout_height= "220DP"Android:background= "#0000FF"//Blue/> </FrameLayout>

6. Nested layout (linear layout and relative layout)

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Vertical" > <TextView Android:id= "@+id/textview1"Android:layout_width= "Match_parent"Android:layout_height= "177DP"Android:background= "#FF4500"Android:text= "111"/> <TextView Android:id= "@+id/textview2"Android:layout_width= "Match_parent"Android:layout_height= "162DP"Android:background= "#BCBFEF"Android:text= "222"/><relativelayout android:layout_width= "Match_parent"Android:layout_weight= "1"Android:layout_height= "406DP" > <TextView android:layout_weight= "1"Android:id= "@+id/textview3"Android:layout_width= "124DP"Android:layout_height= "134DP"Android:background= "#c2c2c2"Android:text= "CCC"/> <TextView Android:layout_torightof= "@id/textview3"Android:id= "@+id/textview4"Android:layout_width= "123DP"Android:layout_height= "136DP"Android:background= "#FF4500"Android:text= "BBB"/> <TextView Android:layout_torightof= "@id/textview4"Android:id= "@+id/textview5"Android:layout_width= "119DP"Android:layout_height= "136DP"Android:layout_weight= "1"Android:background= "#c4c4c4"Android:text= "TTT"/> </RelativeLayout> <TextView Android:id= "@+id/textview4"Android:layout_width= "123DP"Android:layout_height= "136DP"Android:background= "#FF4500"Android:text= "BBB"/> <TextView android:layout_weight= "1"Android:id= "@+id/textview5"Android:layout_width= "119DP"Android:layout_height= "136DP"Android:background= "#c4c4c4"Android:text= "TTT"/> </LinearLayout>

The five main layouts of Android development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.