1. Gravity
Gravity is the center of gravity, which indicates the position of the stop.
Android: gravity refers to the element itself. The text of the element itself is displayed on the left side by changing the attribute settings.
Android: layout_gravity is relative to its parent element, indicating where the element is displayed.
For example, button:Android: layout_gravityThe position of the button on the interface.Android: gravityThe position of the word on the button.
Optional values: top, bottom, left, right, center_vertical, fill_vertical, center_horizontal, fill_horizontal, center, fill, and clip_vertical.
You can select multiple attributes and separate them with "|". The default value is gravity. Left.
2. layout_weight
Layout_weight is used to assign importance values to multiple views in a linear layout.
All views have a value of layout_weight. The default value is zero, which means that a large view occupies much screen space. 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.
For example, we have a text label and two text editing elements in the horizontal direction.
The text label does not specify the layout_weight value, so it occupies the minimum space required. If the layout_weight value of each of the two text editing elements is set to 1, the two are equally divided into the remaining width of the parent view layout (because we declare that the importance of the two is equal ). If the layout_weight value of the first of the two text editing elements is set to 1, and the second is set to 2,
Then 2/3 of the remaining space is allocated to the first space, and 1/3 to the second Space (the smaller the value, the higher the importance ).
<? XML version = "1.0" encoding = "UTF-8" ?> < Linearlayout Xmlns: Android = "Http://schemas.android.com/apk/res/android" Android: layout_width = "Fill_parent" Android: layout_height = "Fill_parent" Android: Background = "@ Drawable/bg02" Android: Orientation = "Horizontal" > < Linearlayout Xmlns: Android = "Http://schemas.android.com/apk/res/android" Android: layout_width = "Fill_parent" Android: layout_height = "Fill_parent" Android: layout_weight = "4" Android: Orientation = "Vertical" > < Textview Android: ID = "@ + ID/txtspace1" Android: layout_width = "Wrap_content" Android: layout_height = "Wrap_content" Android: Text = "" /> </ Linearlayout > < Linearlayout Xmlns: Android = "Http://schemas.android.com/apk/res/android" Android: layout_width = "Fill_parent" Android: layout_height = "Fill_parent" Android: layout_weight = "1" Android: Orientation = "Vertical" > < Textview Android: ID = "@ + ID/txtspace2" Android: layout_width = "Wrap_content" Android: layout_height = "Wrap_content" Android: Text = "" /> < Button Android: ID = "@ + ID/button1" Android: layout_width = "Fill_parent" Android: layout_height = "Wrap_content" Android: Text = "@ String/mn_01" /> < Button Android: ID = "@ + ID/button2" Android: layout_width = "Fill_parent" Android: layout_height = "Wrap_content" Android: Text = "@ String/mn_02" /> < Button Android: ID = "@ + ID/button3" Android: layout_width = "Fill_parent" Android: layout_height = "Wrap_content" Android: Text = "@ String/mn_03" /> < Button Android: ID = "@ + ID/button4" Android: layout_width = "Fill_parent" Android: layout_height = "Wrap_content" Android: Text = "@ String/mn_04" /> </ Linearlayout > < Linearlayout Xmlns: Android = "Http://schemas.android.com/apk/res/android" Android: layout_width = "Fill_parent" Android: layout_height = "Fill_parent" Android: layout_weight = "4" Android: Orientation = "Vertical" > < Textview Android: ID = "@ + ID/txtspace3" Android: layout_width = "Wrap_content" Android: layout_height = "Wrap_content" Android: Text = "" /> </ Linearlayout > </ Linearlayout >