android:orientation= "Vertical" Vertical linear layout, "horizontal" Horizontal line layout
Android:gravity= "Top" (buttom, left, right, center_vertical, fill_vertical, Center_horizontal, Fill_horizontal, Center, fill, clip_vertical, clip_horizontal) controls the alignment of controls in the layout. If a control that does not have a child control sets this property, it indicates the alignment of its contents, such as the alignment of the text inside the TextView, and if the control with the child control sets this property, the alignment of its child controls,gravity if multiple property values need to be set, you need to use the ' | ' method To combine
The difference between android:gravity and android:layout_gravity:
Android:gravity refers to the alignment of the child elements of this element relative to it.
Android:layout_gravity refers to the alignment of the element relative to its parent element.
Android:layout_weight= "1" by setting the control's Layout_weight property to control the relative size of individual controls in the layout, the linear layout is based on the control Layout_ The ratio of the weight value to the sum of the layout_weight value of all controls in its layout assigns the occupied area to the control. There are two buttons in the horizontal layout of the LinearLayout, and the Layout_weight property value of the two button is 1, then both of them will be stretched to half the width of the screen . If layout_weight refers to 0, the control is displayed at the original size and will not be stretched , and for the remaining Layout_weight property values greater than 0, the system will subtract Layout_ Weight the width or height of a control with a property value of 0, and then assigns the width or height of each control to its display by the appropriate proportions, using the remaining width or height.
Cases:
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Vertical"Tools:context=". Linearlayoutactivity "> <LinearLayout android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_weight= "1"android:orientation= "Horizontal" > <Button android:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:layout_weight= "1"Android:background= "#aa0000"android:gravity= "Center_horizontal|center_vertical"Android:text= "first column"android:textsize= "15SP" > </Button> <Button android:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:layout_weight= "1"Android:background= "#00aa00"android:gravity= "Center_horizontal"Android:text= "second column"android:textsize= "15SP" > </Button> <Button android:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:layout_weight= "1"Android:background= "#0000aa"android:gravity= "Center|bottom"Android:text= "third column"android:textsize= "15SP" > </Button> <Button android:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:layout_weight= "1"Android:background= "#aaaa00"android:gravity= "Bottom"Android:text= "Fourth column"android:textsize= "15SP" > </Button> </LinearLayout> <LinearLayout android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_weight= "1"android:orientation= "Vertical" > <Button android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_weight= "1"android:gravity= "Bottom"Android:text= "Line 1th"android:textsize= "15SP" > </Button> <Button android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_weight= "1"android:gravity= "Bottom"Android:text= "line 2nd"android:textsize= "15SP" > </Button> <Button android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_weight= "1"android:gravity= "Bottom"Android:text= "line 3rd"android:textsize= "15SP" > </Button> <Button android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:layout_weight= "1"android:gravity= "Bottom"Android:text= "Line 4th"android:textsize= "15SP" > </Button> </LinearLayout></LinearLayout>
LinearLayout Linear layout in Android