XML layout file in Android

Source: Internet
Author: User

linearlayout and relativelayout

Common attributes :
Associating secondary controls with BTN in Java code
Android:id= "@+id/btn"

Control 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 arrangement:
android:orientation= "Horizontal"//horizontal arrangement
android:orientation= "vertical"//vertical arrangement

Control spacing:
android:layout_marginleft= "5dip"//distance to the left
android:layout_marginright= "5dip"//distance to the right
android:layout_margintop= "5dip"//Distance above
android:layout_marginright= "5dip"//Distance below

Control Display Location:
android:gravity= "center"//left,right, top, bottom
Android:gravity= "Center_horizontal"

Android:layout_gravity is the gravity direction of this element to the parent element.
The Android:layout_gravity property sets the display position of the control itself relative to the parent control
Android:gravity is the gravity direction of all child elements of this element.

Android:layout_gravity= "Center_vertical"
Android:layout_gravity= "left"
Android:layout_gravity= "Left|bottom"


TextView Chinese Text font:
android:text= "@String/text1"//defines the value of Text1 in String.xml
Android:textsize= "20SP"
Android:textcolor= "#ff123456"
Android:textstyle= "bold"//Normal (normal), italic (italic), coarse italic (bold_italic)

Defines whether the control is visible:
android:visibility= "visible"//Visible
android:visibility= "Invisible"//is not visible, but the position occupied in the layout is still
Android:visibility= "Gone"//not visible, completely disappearing from layout

To define a background picture:
android:background= "@drawable/img_bg"//IMG_BG is a picture under drawable

Seekbar control background picture and maximum value
android:progressdrawable= "@drawable/seekbar_img"
android:thumb= "@drawable/thumb"
Android:max = "60"

Valid only in Relativelayout:
In the relative position of the father's layout
Android:layout_alignparentleft= "true"//on the left side of the layout
Android:layout_alignparentright= "true"//on the right side of the layout
Android:layout_alignparenttop= "true"//above the layout
Android:layout_alignparentbottom= "true"//below the layout

In the relative position of a control
android:layout_torightof= "@id/button1"//on the right side of the control button1, not just close to the
android:layout_toleftof= "@id/button1"//on the left side of the control button2, not just close to the
android:layout_below= "@id/button1"//under control Button1, not just directly below
Android:layout_above= "@id/button1"//under control Button1, not just directly below

Definition and a control pair of odd
android:layout_aligntop= "@id/button1"//and alignment on controls button1
android:layout_alignbottom= "@id/button1"//and controls button1 aligned
android:layout_alignleft= "@id/button1"//and control Button1 left justified
android:layout_alignright= "@id/button1"//and control button2 right align


Android:layout_centerhorizontal= "true"//Horizontal Center
Android:layout_centervertical= "true"
Android:layout_centerinparent= "true"

Valid only in LinearLayout
To set a control's proportional value in a row or column
android:layout_weight= "1"

XML layout file in Android

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.