Android layout XML Summary

Source: Internet
Author: User
Tags xml attribute

Common attributes:

JavaCodeAssociate the control with btn1

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

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

 

Widget display position

 

Android: gravity = "center" // left, right, top, bottom

 

Android: gravity = "center_horizontal"

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"

 

Textview attributes

 

Android: text = "@ string/text1" // define the value of text1 in string. xml

 

Android: textsize = "20sp"

 

Android: textcolor = "# ff123456"

 

Android: textstyle = "bold" // normal, italic, and bold_italic are set in combination. Example: bold | Italic

Text-related attributes

 

Android: hint prompt when the text content is empty

Android: textcolorhight: highlighted color when the text is selected

 

Control of input content

 

Android: Number can only be a number. Value range [integer, decimal, signed], which can be set in combination. Example: integer | signed

 

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"

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

Definition and 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

 

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"

XML Attribute of view:

Known direct subclass:

Analogclock, imageview, keyboardview, progressbar, surfaceview, textview, viewgroup, viewstub

 

Known indirect subclass:

 

abslistview, absseekbar, absspinner, vertex, adapterview, appwidgethostview, callback, button, checkbox, checkedtextview, chronometer, distance, datepicker, dialerfilter, digitalclock, edittext, distance, distance, gallery, glsurfaceview, gallery, gallery, gridview, layout, imagebutton, imageswitcher, linearlayout, listview, mediacontroller, metrics, radiogroup, ratingbar, relativelayout, scrollview, seekbar, category, spinner, tabhost, tabwidget, tablelayout, tablerow, textswitcher, timepicker, togglebutton, cursor, videoview, viewanimator, viewflipper, viewswitcher, Web View, zoombutton, zoomcontrols

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.