Android-UI component (1): layout manager

Source: Internet
Author: User
Tags xml attribute

This section describes the layout manager derived from ViewGroup.

The following shows the class diagram of the android layout manager:


The graphic user interface of android applications has good platform independence, that is, the layout manager is used to manage the component distribution and size, rather than directly setting the component location and size.

1. LinearLayout class (linear layout ):

The components in the container can be arranged one by one, and LinearLayout can control the arrangement (horizontal or vertical) of each component ).

The following shows the XML attributes supported by LinearLayout and related methods: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140409/2014040908503317.jpg" alt = "\">

All child elements in LinearLayout are controlled by LinearLayout. LayoutParams,

Common XML attributes supported by LinearLayout. LayoutParams sub-elements and related methods:



2. TableLayout class (table layout ):

TableLayout inherits LinearLayout, which is essentially a linear layout manager. TableLayout manages UI components in the form of rows and columns. TableLayout does not need to specify how many rows and columns are contained, you can add other components such as TableRow to control the number of rows and columns of a table.

In table layout, the column width is determined by the cell with the largest width in the column. The layout width of the entire table depends on the width of the parent container (by default, the parent container is fully occupied)

In TableLayout, you can set the behavior of cells as follows:

Shrinkable: When a column is set to Shrinkable, the width of all cells in the column can be reduced to ensure that the table can adapt to the width of the parent container.

Stretchable: When a column is set to Stretchable, the width of all cells in the column can be stretched to ensure that the component can fully fill the free space of the table.

Collapsed: If a column is set to Collapsed, all cells in the column are hidden.

TableLayout inherits LinearLayout, which supports all XML attributes supported by LinearLayout. In addition, TableLayout supports the following attributes:


For column sequence numbers, we usually start from 0. 0 indicates the first column, 1 indicates the 2nd columns, and goes down in sequence...


3. FrameLayout class (frame layout ):

As you can see from the layout manager class diagram at the beginning, FrameLayout directly inherits from ViewGroup.

FrameLayout creates a blank area for each component. Each child component occupies one frame, and these frames are automatically aligned according to the gravity attribute.

Common XML attributes and optical method for FrameLayout:


FrameLayout sub-elements are also controlled by FrameLayout. LayoutParams. The blog provides an example of the corresponding "Neon effect" of FrameLayout.


4. RelativeLayout class (relative layout ):

The position of the child components in the relative layout container is always determined by the sibling component and parent container. This layout method is called relative layout.

For example, if the position of component A is determined by the position of component B, you must first define the position of component B before defining component.

RelativeLayout supports the following XML attributes:


To control the layout distribution of RelativeLayout layout neutron components, RelativeLayout provides an internal class: RelativeLayout. LayoutParams, which provides a large number of XML attributes to control the layout distribution:

Below are the XML attributes set to true and false for RelativeLayout. LayoutParams.


The following is the property of setting RelativeLayout. LayoutParams to another UI component ID:




In addition, RelativeLayout. LayoutParams inherits from android. view. ViewGroup. MarginLayoutParams. Each child component in the RelativeLayout layout container can be specified as the XML Attribute supported by android. view. ViewGroup. MarginLayoutParams.


5. GridLayout class (grid layout ):

This is the layout manager added to android4.0, which can only be used in Versions later than android4.0.

GridLayout is similar to the table label in HTML. It divides the entire container into rows * columns grids, and each grid can be placed with one component, you can also set how many columns A component spans and how many rows a component spans.

Common XML attributes and related methods of GridLayout are listed below:


To control the layout distribution of child components in the GridLayout layout container, GridLayout provides an internal class: GridLayout. layoutParams, which provides XML attributes to control the layout distribution of sub-components in the GridLayout layout container:

Seo8L3A + Environment + tcRZ1/ix6133 vcd4kpha + Environment/Environment + CjxwPs/Cw + Environment + CjxwPjxpbWcgc3JjPQ = "http://www.2cto.com/uploadfile/Collfiles/20140409/2014040908503632.jpg" alt = "">

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.