Various alignment issues with Android layouts

Source: Internet
Author: User

First, LinearLayout (linear layout)

Provides a model for the horizontal vertical arrangement of controls, and controls the relative size of individual controls in the layout by setting the weight layout parameters of the child controls

Small.

Horizontal (vertical) vertical (horizontal)

Fill-parent: Fills the entire screen

Wrap-content: Just right for the size of the control content

Alignment Gravity Value:

Top: Does not change size, position is placed on top of container

Bottom: Does not change size, position is placed at the bottom of the container

Left: does not change size, position is placed on container

Right: does not change size, position is placed on container

Center_vertical: Does not change size, position is placed in the vertical central part of the container

Center_horizontal: Does not change size, position is placed in the horizontal central part of the container

Center: does not change size, position is placed in the central part of the container's horizontal and vertical

Fill_vertical: If possible, the longitudinal extension can fill the container

Fiil_horizontal: If possible, the horizontal extension can fill the container

Fiil: If possible, vertical and horizontal extension fills the container

Second, absolutelayout (coordinate layout)



You can have child elements specify accurate x/Y coordinate values and display them on the screen. (0, 0) is the upper-left corner, and when you move down or to the right, the coordinate value

Become larger. Absolutelayout does not have a page border, allowing elements to overlap each other (although not recommended). We generally do not recommend the use of

Absolutelayout, unless you have a valid reason to use it, because it makes the interface code too rigid, so that on different devices may

Can't work very well.


android:layout_x= "40px"

Android:layout_y= "56px" to determine the position of the control

Third, relativelayout (relative layout)



Allows child elements to specify their location relative to other elements or parent elements (specified by ID). So you can align to the right, or up and down,



Or placed in the middle of the screen to arrange two elements. Elements are arranged sequentially, so if the first element is in the center of the screen, the relative



Other elements of this element will be arranged in the relative position of the center of the screen. If you use XML to specify this layout, before you define it



, the element being associated must be defined.



Android:layout_centerinparent, places the current control in the horizontal and vertical central part of the parent control



Android:layout_centerhorizontal to place the current control in the central part of the parent control's landscape



Android:layout_centervertical to place the current control in the central part of the parent control's portrait



Android:layout_alignparentbottom to align the bottom of the current control with the bottom of the parent control



Android:layout_alignparentleft to align the left and parent controls of the current control



Android:layout_alignparentright, aligns the right end of the current control with the right end of the parent control



Android:layout_alignparenttop to align the top of the current control with the top of the parent control



Android:layout_alignparentbottom to align the bottom of the current control with the bottom of the parent control

Android:layout_above the bottom of the control to the control of the given ID




Android:layout_below the top of the control to the control of the given ID


Android:layout_toleftof aligns the right edge of the control with the left edge of the control for the given ID


Android:layout_torightof aligns the left edge of the control with the right edge of the control for the given ID




Android:layout_alignbaseline the baseline of the control's baseline and the given ID of the control
Android:layout_alignbottom the bottom edge of the control with the bottom edge of the given ID control
Android:layout_alignleft aligns the left edge of the control with the left edge of the given ID control
Android:layout_alignright aligns the right edge of the control with the right edge of the given ID control
Android:layout_aligntop aligns the top edge of the given control with the top of the given ID control
android:layout_marginbottom/layout_marginleft/layout_marginright/layout_margintop= "30px"



Empty the corresponding pixel space at the bottom/left/right/top of the current control



Four, Framelayout (single frame layout)



Is the simplest of a layout object. It is customized as a blank alternate area on your screen, after which you can populate a single object


-for example, a picture you want to publish. All child elements will be fixed in the upper left corner of the screen; You cannot be a child in Framelayout

element to specify a location. The next child element will overwrite the padding directly above the previous child element, blocking them partially or completely (unless

The latter child element is transparent).

android:src= the "@drawable/" property specifies the file location of the desired picture, and when you display the picture with ImageView, you should also use

Android:src Specify the picture to display



V. Tablelayout (table layout)



Manage child controls in the form of rows, each of which behaves as a TableRow object, TableRow can also add child controls

Android:collapsecolumns= "n" hides the column N of the TableRow inside the Tablelayout

Android:stretchcolumns= "n" to set column n as an extensible column

Android:shrinkcolumns= "n" to set column N to be a shrinking column

Various alignment issues with Android layouts

Related Article

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.