Android development study notes (four) linear layout LinearLayout

Linear Layout (LinearLayout) contains a lot of knowledge points, put on the renderings and source code for specific analysis.
Effect picture:
Insert picture description here
source code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="300dp"
    android:layout_height="300dp"
    android:orientation="horizontal"
    android:layout_gravity="center"
    android:gravity="center|top"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮1"
        android:layout_weight="1">

    </Button>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮2"
        android:layout_weight="1">
    </Button>

    <LinearLayout android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        xmlns:android="http://schemas.android.com/apk/res/android">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮3"
        android:layout_weight="1">

    </Button>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮4">
    </Button>
    </LinearLayout>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮5">

    </Button>

</LinearLayout>

android:orientation is a linear arrangement, divided into horizontal horizontal and vertical vertical
android:layout_gravity is the relative position of the entire LinearLayout in the parent container. When many attributes are used, check it, for example, center is the center
android:gravity. The relative position
android:layout_weight in the container is the weight. The weight determines the proportion of the space occupied by the element in the layout. If the weight is the same, the space is equally divided.
Nested layout: just nest one layer in LinearLayout, as shown in the button 3 effects shown

Guess you like

Origin blog.csdn.net/qq1198768105/article/details/113820565