Android Layout XML Attribute, androidlayout

Source: Internet
Author: User
Tags xml attribute

Android Layout XML Attribute, androidlayout

Reprinted from and do a small amount of Add: http://www.cnblogs.com/playing/archive/2011/04/07/2008620.html

 

Layout plays a significant role in quickly setting up the interface and improving the adaptability of the interface on screens with different resolutions. Here we will briefly introduce Layout of Android and study its implementation.

Android has Layout: LinearLayout, TableLayout, RelativeLayout, FrameLayout, GridLayout, and AbsoluteLayout.

XML Attribute of the View to be arranged in Layout:

1. In several LayoutItemCommon XML attributes:

  • (1) layout_width
  • (2) layout_height

Note: (1) and (2) are used to determine the width and height of the View placed in Layout: they may be fill_parent, wrap_content, or fixed pixel values.

  • (3) layout_marginLeft ---> paddingLeft
  • (4) layout_marginTop ---> paddingTop
  • (5) layout_marginRight ---> paddingRight
  • (6) layout_marginBottom ---> paddingBottom
  • (Supplemented) layout_margin ---> padding

Note: (3) (4) (5) (6) a View placed in Layout is expected to be a distance between the View and the border of Layout or other views.

Android: paddingLeft: layout_marginLeft:

Padding margin is the meaning of margins. The key issue is to understand what the margins are.
Padding is the margin of the control content relative to the control edge.If it is a control, it is the distance between the spatial content and the control edge. But in the parent control, the distance between the child control and the edge of the parent control is set.

Layout_margin is the margin of the control edge relative to the parent space.This should be divided into two la S. If it is a linear layout, the space in it is arranged in one row, it will be the distance from the next control. If the relative layout is not set, only the margin is generated for the parent control.

  • (7) layout_gravity

Note: (7) determine the position of a View in Layout.

Difference between android gravity and layout_gravity

Android: The gravity attribute limits the content of the view. For example, you can set the text on the button to the left and right of the view.
Android: layout_gravity is used to set the position of the view relative to the parent view. For example, if a button is in linearlayout, you can set this attribute by placing it in the left-to-right position.

This explains what we have to do with the outermost layout, and then we have several la S. If we want to make these la s depend on the bottom, you can set androi: gravity = "botton" in the attribute of the outermost layout, because gravity is used for the content.

FrameLayoutIs the simplest Layout and only has these attributes. Layer-by-layer layout.

LinearLayoutThere will also be:

  • (8) layout_weight

Note:(8) It is used to distribute the remaining space after all sub-views are arranged in LinearLayout to each View with this attribute according to their layout_weight.

TableLayoutTableRow is a horizontal (horizontal) LinearLayout

RelativeLayoutThere are 16 align-related XML attributes:

  • (9) layout_alignParentBottom: low-end alignparentbottom of the current control and the low-end alignparentbottom of the parent control (coincidence)
  • (10) layout_alignParentLeft: Align the left end of the current control with the left end of the parent control (coincidence)
  • (11) layout_alignParentRight: Align the right of the current control with the right of the parent control (coincidence)
  • (12) layout_alignParentTop: the upper end of the current control is aligned with the upper end of the parent control (coincidence)
  • (13) layout_centerHorizontal the current control is located in the horizontal middle of the parent control (in the middle of the horizontal direction)
  • (14) layout_centerInParent the current control is located in the middle of the vertical direction of the parent control (in the middle of the vertical direction)
  • (15) layout_centerVertical the current control is located in the vertical middle of the parent control (center on the plane)
  • (16) layout_above: place the current control above the id control given
  • (17) layout_below: place the current control below the id control given
  • (18) layout_toLeftOf: place the current control on the left of the id Control
  • (19) layout_toRightOf: place the current control on the right of the given id Control
  • (20) layout_alignBottom: make the current control and the bottom part of the id control overlap(Note that the id control can be used for alignment)
  • (21) layout_alignLeft: overlap the current control with the left side of the id Control
  • (22) layout_alignRight: make the current control coincide with the right side of the id Control
  • (23) layout_alignTop: the current control overlaps with the top of the id Control
  • (24) layout_alignBaseline: The BaseLine of the current control overlaps with the BaseLine of the id control t. This is mainly used for Label or other widgets containing text.

Note: (9) to (24) is used to determine the position of the View in RelativeLayout relative to other views in Layout or Layout.

GridLayoutGrid layout

  • (25) columnCount: set the number of columns in the grid.
  • (26) rowCount: set the number of rows in the grid.
  • (27) layout_column sets the column number of the child component in gridlayout.
  • (28) layout_columnSpan sets the number of rows that the child widget spans horizontally in gridlayout.
  • (29) layout_gravity sets the way in which the sub-component occupies the space of the grid.
  • (30) layout_row sets the row number of the Child widget in gridlayout.
  • (31) layout_rowSpawn sets the number of lines that the child component spans vertically in gridlayout.

AbsoluteLayoutEach sub-component has two attributes.

  • (32) layout_x
  • (33) layout_y

 

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.