Android learning notes: 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. XML attributes common to items in Layout:

(1) layout_width

(2) layout_height

(3) layout_marginLeft

(4) layout_marginTop

(5) layout_marginRight

(6) layout_marginBottom

(7) layout_gravity

FrameLayout is the simplest Layout and has only these attributes.

LinearLayout will also have:

(8) layout_weight

The TableLayout row TableRow is a horizontal) LinearLayout.

RelativeLayout has 16 align-related XML attributes:

(9) layout_abve

(10) layout_alignBaseline

(11) layout_alignBottom

(12) layout_alignLeft

(13) layout_alignParentBottom

(14) layout_alignParentLeft

(15) layout_alignParentRight

(16) layout_alignParentTop

(17) layout_alignRight

(18) layout_alignTop

(19) layout_below

(20) layout_centerHorizontal

(21) layout_centerInParent

(22) layout_centerVertical

(23) layout_toLeftOf

(24) layout_toRightOf

(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) (4) (5) (6) the View placed in Layout is expected to be a distance between it and the border of Layout or other views.

(7) determine the position of the View in Layout.

(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.

(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.

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.