Comparison between linear layout LinearLayout and RelativeLayout, and relativelayout

Source: Internet
Author: User

Comparison between linear layout LinearLayout and RelativeLayout, and relativelayout

Between LinearLayout and RelativeLayout:

Common attributes:
Associate a control using btn1 in java code
Android: id = "@ + id/btn1"

Widget width
Android: layout_width = "80px" // "80dip" or "80dp "()
Android: layout_width = "wrap_content"
Android: layout_width = "match_parent"

Control height
Android: layout_height = "80px" // "80dip" or "80dp"
Android: layout_height = "wrap_content"
Android: layout_height = "match_parent"

Control Layout
Android: orientation = "horizontal"
Android: orientation = "vertical"

Widget spacing

// The distance between the control and the control/Layout


Android: layout_marginLeft = "5dip" // left
Android: layout_marginRight = "5dip" // distance to the right
Android: layout_marginTop = "5dip" // distance from above
Android: layout_marginRight = "5dip" // distance from the following

Android: paddingLeft = "5dip"


Widget display position (alignment Mode)

// Display alignment in the control such as text in the control
Android: gravity = "center" // left, right, top, bottom
Android: gravity = "center_horizontal"

Android: gravity = "center_vertical"

-----------------------------------------
// Align controls with layout pages
Android: layout_gravity is the gravity direction of the element to the parent element.
Android: layout_gravity attribute sets the display position of the control relative to the parent control.
Android: gravity is the gravity direction of all child elements of the current element.

Android: layout_gravity = "center_vertical"
Android: layout_gravity = "left"
Android: layout_gravity = "left | bottom"


Text font in TextView
Android: text = "@ String/text1" // define the value of text1 in string. xml
Android: textSize = "20sp" // use sp in font
Android: textColor = "# ff123456"
Android: textStyle = "bold" // normal, italic, and bold_italic)

In TextView, control it to end...

Android: ellipsize = "end"

Only one row

Android: singleLine = "true"

Define whether the control is visible
Android: visibility = "visible" // visible
Android: visibility = "invisible" // invisible, but the position occupied in the layout is still
Android: visibility = "gone" // invisible, completely removed from the Layout

Define background image
Android: background = "@ drawable/img_bg" // img_bg indicates an image under drawable.

Seekbar control background image and maximum value
Android: progressDrawable = "@ drawable/seekbar_img"
Android: thumb = "@ drawable/thumb"
Android: max = "60"

Android: layout_alignWithParentIfMissing = "true"

Valid only in RelativeLayout:
Relative Position of the parent Layout
Android: layout_alignParentLeft = "true" // on the left of the layout
Android: layout_alignParentRight = "true" // on the right of the Layout
Android: layout_alignParentTop = "true" // above the Layout
Android: layout_alignParentBottom = "true" // under the Layout

Relative Position of a widget
Android: layout_toRightOf = "@ id/button1" // on the right side of the control button1, not just close
Android: layout_toLeftOf = "@ id/button1" // on the left side of the control button2, not just close
Android: layout_below = "@ id/button1" // under the control button1, not just at the bottom
Android: layout_above = "@ id/button1" // under the control button1, not just the front and bottom

Define alignment with a widget
Android: layout_alignTop = "@ id/button1" // aligntop = "@ id/button1"
Android: layout_alignBottom = "@ id/button1" // align with the lower part of the control button1
Android: layout_alignLeft = "@ id/button1" // align left with the control button1
Android: layout_alignRight = "@ id/button1" // right-aligned with the control button2

Widget relative to layout
Android: layout_centerHorizontal = "true" // horizontally centered
Android: layout_centerVertical = "true"
Android: layout_centerInParent = "true"

Valid only in LinearLayout
Sets the percentage of controls in a row or column.
Android: layout_weight = "1

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.