Android base TOP3: Features of linear layout, common attributes, and weight values, androidtop3
Linear layout is a horizontal or vertical layout of views;
Common attributes:
Androuid: orientation: indicates the layout direction
- The vertical value indicates the vertical layout.
- The value horizontal indicates horizontal layout.
Android: gravity indicates view alignment
- Content includes TOP, bottom, left, right, center_vertical, center_horizontal, center
- You can use "|" to separate multiple values.
The following attributes can be used for a view in the layout:
Android: layout_gravity indicates the alignment of a single view
Android: layout_weight indicates the proportion of the size of a single view
- When Layout_weight is 0, the View Size is determined.
- When layout_weight is greater than 0, the view is stretched according to the specific gravity in the linear layout direction.
Code Demonstration:
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="horizontal" > 6 <Button 7 android:layout_width="200dp" 8 android:layout_height="100dp" 9 android:text="adaflkjn"10 android:gravity="bottom|center_horizontal"/>11 12 </LinearLayout>
Android: gravity: determines the position of elements in the control.
<Button android:layout_width="200dp" android:layout_height="100dp" android:text="adaflkjn" android:layout_gravity="center"/>
Android: layout_gravity indicates the position of the current element in the parent element.
Weight applications
<EditText android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:hint="sdaf"/> <Button android:layout_width="1dp" android:layout_height="wrap_content" android:layout_weight="0" android:text="klndgjl" />
<TextView android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_weight = "0" android: text = "weight 0" android: background = "# FFF0F5"/> <TextView android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: text = "weight is 1" android: layout_weight = "1" android: background = "#800080"/> <TextView android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: text = "weight is 4" android: layout_weight = "4" android: background = "#4B0082"/>