Linerlayout is a row (column) that can only place the linear layout of one control. Therefore, when many controls need to be listed, you can use this pull.
Code:
Main. xml
<?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:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:textSize="15pt" android:background="#aa0000" android:layout_weight="1" android:text="@string/hang1" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:textSize="15pt" android:background="#00aa00" android:layout_weight="1" android:text="@string/hang2" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:textSize="15pt" android:background="#0000aa" android:layout_weight="1" android:text="@string/hang3" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:textSize="15pt" android:background="#aaaa00" android:layout_weight="1" android:text="@string/hang4" /> </LinearLayout>
Code in string. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<String name = "hello"> Hello world, androidbooklinerlayoutp101activity! </String>
<String name = "app_name"> vertical linear layout </string>
<String name = "hang1"> first line </string>
<String name = "hang2"> Row 2 </string>
<String name = "hang3"> Row 3 </string>
<String name = "hang4"> row 4 </string>
</Resources>
Resolution:
Orientation = "vertical" indicates the vertical linear layout.
Fill_parent indicates that the control fills the screen
Wrap_content indicates that the width or height of the control varies with the text field.
Gravity specifies the location, top, bottom, right, and so on
Layout_weight: The default value is 0, indicating the size of the view to occupy. If the value is greater than 0, it must be separated by the available space of the parent view, the split size depends on the size of the value and the current proportion.
Android: text = "@ string/hang1": reference the hang1 text in string. This is easy to understand. As defined in this way
Android: Background = "# aa0000" background color
Change the vertical above to the Android: Orientation = "horizontal" level, and this effect will appear.