This is the 26th day of my participation in the August Text Challenge.More challenges in August

Introduction to the

A LinearLayout is a LinearLayout. The current layout only supports its sub-layouts in the form of lines. LinearLayout supports two kinds of arrangements, vertical and horizontal.

Orientation of arrangement

The LinearLayout supports two kinds of arrangement: vertical and horizontal. The default layout is horizontal. If no arrangement is specified, the AS tool will mark the layout in red when it exceeds the screen width

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".LinearLayoutActivity">
    <Button
        android:text="First button"
        android:layout_marginEnd="20dp"
        android:layout_width="200dp"
        android:layout_height="50dp"/>
    <Button
        android:text="Second button"
        android:layout_width="match_parent"
        android:layout_height="50dp"/>
</LinearLayout>
Copy the code

orientationSpecified asverticalwhen

Weight layout_weight

Note that if the weight is specified according to the orientation arrangement, the corresponding width and height should be set to 0. For example, if you want to specify the weight of the control’s width, you need to set layout_width to 0dp

The level of the weight

Vertical weight

WeightSum Number of weightSum

LinearLayout can specify the sum of the weights within the current layout, for example, specify that the current layout is divided into six equal parts, one for each of the two controls, and the rest is left blank

If the total weight of the control exceeds the number of weights specified by the parent layout, the total weight of the parent layout is displayed at most. If no weight is specified by the parent layout, the total weight of the control is the number of weightSum of the parent layout

Basic attributes

Android :layout_width control width, which can be set to wrAP_content adaptive,match_parent fills parent form and custom width Android :layout_height control height, can be set to wrap_content adaptive,match_parent fills the parent form and custom height Android :orientation Horizontal (default) vertical Android :weightSum Android :layout_weight Specifies the weight of the current control android:layout_gravity Position relative to the parent layout Android: gravity to specify the location of the layout, optional has a top, bottom, left, right, center_vertical, fill_vertical, center_horizontal, fill_horizontal, center, fill,clip_vertical,clip_horizontal,start,end