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
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"
Text font in TextView
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)
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"