Android Learning Note 6:6 Large layout

Source: Internet
Author: User
Tags xml attribute

Six main interface layouts include: linear layout (linearlayout), frame layout (framelayout), table layout (tablelayout), relative layout (relativelayout), Absolute layout (absolutelayout) and Grid layout (GridLayout).

1. LinearLayout Linear layout

The components in the LinearLayout container are arranged one by one, and by controlling the Android:orientation property, you can control whether the components are arranged horizontally or vertically.

Common XML attributes of LinearLayout and related methods
XML Properties Related Methods Description
Android:gravity setgravity (int) To set the alignment of components within a layout manager
Android:orientation setorientation (int) Sets the arrangement of components within the layout manager, which can be set to one of horizontal, vertical two values

Among them, the Gravity property supports top, left, right, center_vertical, fill_vertical, Center_horizontal, fill_horizontal, center, fill, Clip_ Vertical, Clip_horizontal. You can also specify a combination of multiple alignment options at the same time.

Common XML attributes and methods supported by LinearLayout sub-elements

XML Properties Description
Android:layout_gravity Specifies how the child element is aligned in the LinearLayout
Android:layout_weight Specifies the weight that child elements occupy in LinearLayout

2. tablelayout Table layout

Tablelayout inherits from Linearout, which is still essentially a linear layout manager. Table layouts Manage UI components in rows and columns, without explicitly declaring how many rows and columns are included, but rather by adding tablerow, other components to control the number of rows and columns of the table.

Adding a TableRow to each tablelayout represents a row;

Adding a sub-component to each TableRow represents a column, which can occupy n columns by android:layout_span= "n" set sub-components;

If you add a component directly to Tablelayout, the component will take up a row directly;

3. Framelayout Frame Layout

Framelayout directly inherits from the ViewGroup component. The frame layout creates a blank area (called a frame) for each component that is added to it, and each subassembly occupies one frame, and the frames are automatically aligned according to the Gravity property.

If more than one control is defined in the same place, the subsequent control overrides the preceding space.

4. Relativelayout the XML attribute can only be set to Boolean in relative layout relativelayout.layoutparams
XML Properties Description
Android:layout_centerhorizontal Sets whether the subassembly is centered horizontally in the layout container
Android:layout_centervertical
Android:layout_centerparent
Android:layout_alignparentbottom
Android:layout_alignparentleft
Android:layout_alignparentright
Android:layout_alignparenttop
Relativelayout.layoutparams attribute value is an XML attribute of another UI component ID
XML Properties Description
Android:layout_torightof Controls the sub-component on the right side of the given ID component
Android:layout_toleftof
Android:layout_above
Android:layout_below
Android:layout_aligntop
Android:layout_alignbottom
Android:layout_alignright
Android:layout_alignleft
5. GridLayout Grid Layout

GridLayout is a Android4.0 added grid layout control, similar to the previous tablelayout, which divides the entire container into Rowsxcolumns meshes , where each grid can place a component. Performance and function are better than tablelayout, such as gridlayout layout of cells can span more than a row, and tablelayout is not, in addition, its rendering speed is faster than tablelayout.

GridLayout provides the setrowcount (int) and setcolumncount (int) methods to control the number of rows and columns of the grid .

GridLayout common XML properties and method descriptions
XML Properties Related Methods Description
Android:alignmentmode Setalignmentmode (int) Set the alignment mode used by the layout manager
Android:columncount Setcolumncount (int) Set the number of columns for this grid
Android:columnorderpreserved Setcolumnorderpreserved (Boolean) Sets whether the grid container retains the serial number
Android:roecount Setrowcount (int) Set the number of rows for this grid
Android:roworderpreserved Setroworderpreserved (Boolean) Sets whether the grid container retains row numbers
Android:usedefaultmargins Setusedefaultmargins (Boolean) Sets whether the layout manager uses the default page margins
Common XML properties and method descriptions in which the components are used
XML Properties Description
Android:layout_column Set the first column of the component in GridLayout
Android:layout_columnspan Sets the sub-component to span several columns across the GridLayout
Android:layout_gravity Sets how the subassembly occupies the space of the grid
Android:layout_row Sets the number of lines of the subassembly in GridLayout
Android:layout_rowspan Sets the subassembly to span several lines vertically on the GridLayout
6. Absolutelayout Absolute Layout (not recommended)

That is, Android does not provide any layout control, but rather the developer's own x-coordinate, y-coordinate to control the position of the component. Each component can specify the following two XML attributes:

    • layour_x;
    • layout_y;

Android Learning Note 6:6 Large layout

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.