Android linear layout LinearLayout (7) and linearlayout
I. First, I want to know several attributes:
1. Layout
1) android: orientation = "vertical" vertical layout
2) android: orientation = "horizontal" horizontal layout
2. control content height and width Layout
1) android: layout_width = "match_parent", full of the screen. [Match parent window]
2) for android: layout_height = "wrap_content", the layout element will be changed based on the content. [The content includes]
3. layout Ratio
All views have a layout_weight value. The default value is zero, which means that the size of the view to be displayed occupies the size of the blank screen. If a value higher than zero is assigned, the free space in the parent view is split, the split size depends on the layout_weight value of each view and the ratio of the layout_weight value in the current screen layout to the layout_weight value in the screen layout of other views.
2. The following two examples are implemented:
1) Place the three buttons horizontally
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="mc" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="m+" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="m-" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="mr" /> </LinearLayout>
Use layout_weight to make the three buttons occupy the same proportion.
2. Two buttons: three buttons at the first layer and two buttons at the second layer
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="3" android:orientation="horizontal" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="1" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="2" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="3" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="3" android:orientation="horizontal" > <Button android:layout_width="0px" android:layout_height="wrap_content" android:layout_weight="2" android:text="0" /> <Button android:layout_width="0px" android:layout_height="wrap_content" android:layout_weight="1" android:text="." /> </LinearLayout> </LinearLayout>
First use a large layer and set the weight ratio to 3. The weight of the first button on the second layer accounts for 2/3 of the layer.