Android layout XML attributes

Source: Internet
Author: User
Tags xml attribute

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: framelayout, linearlayout, tablelayout, relativelayout, 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.

  • (7) layout_gravity

Note: (7) determine the position of a view in layout.

FramelayoutIs the simplest layout and only has these attributes.

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.

    ++ ++

    According to the android documentation, Android will traverse the tree composed of layou and view nesting twice, one is the measure call, used to determine the size of layout or view; the other is the layout call, used to determine the location of layout or view. Of course, my own shanzhai implementation merged the two calls. That is, layout performs a measure operation on itself before the layout, and then recursively calls the Layout Method on The View. The size of this is definitely determined. Then, the gravity or align attribute is used to locate the location with the determined size, and the margin is used to adjust the location.

    ++ ++

    Supplement:

    1. Differences between Android: paddingleft and Android: 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.
    Layout_margin is the margin of the control edge relative to the parent space.

    2. Differences 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.

    Reprinted from: http://www.cnblogs.com/playing/archive/2011/04/07/2008620.html

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.