Android布局之线型布局

今天我们来学习Android里面入门的线型布局(***LinearLayout***)。
    总的来说线型布局分为水平布局和垂直布局

        垂直布局的关键字是(**vertical**)
        水平布局的关键字是(**horizontal**)

这里写图片描述

由于线型代码比较单一,我带入一个代码块
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout//设置一个容器
        android:layout_width="wrap_content"//字体多大高度就多高
        android:layout_height="match_parent"//长度占满一行
        android:layout_weight="1"
        android:orientation="vertical"//这是设置垂直布局|也可以设置水平布局
        >
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="左上"
            />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:gravity="bottom"//设置方向
        >
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="左下"
            />
    </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        >
        <Button//设置按钮
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:text="中间"
            />


    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:gravity="right"
        >
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="右上"

            />
       <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_weight="1"
           android:orientation="vertical"
           android:gravity="bottom|right"
           >
           <Button
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"


               />

       </LinearLayout>


    </LinearLayout>


</LinearLayout>

猜你喜欢

转载自blog.csdn.net/lka0224/article/details/72892278