1. 程式人生 > >線性佈局(重點) LinearLayout 幀佈局FrameLayout

線性佈局(重點) LinearLayout 幀佈局FrameLayout

幀佈局例項

  android:layout_margin="20dp"(內邊距)
    android:background="@color/green"(顏色)
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    

    <TextView
        android:layout_margin="20dp"(外邊距)
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/red"(顏色)
        />

下圖為基本效果
在這裡插入圖片描述

<?xml version="1.0" encoding="utf-8"?>
<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"

    android:orientation="vertical"(橫向排列還是縱向排列)
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="左上按鈕" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="210dp"(邊距)
            android:text="右上按鈕" />
    </LinearLayout>


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="150dp"(邊距)
            android:layout_marginTop="180dp"(邊距)
            android:text="居中按鈕" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="180dp"(邊距)

            android:text="左下按鈕" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="210dp"(邊距)
            android:layout_marginTop="180dp"(邊距)
            android:text="右下按鈕" />
    </LinearLayout>

</LinearLayout>

程式碼效果如下圖所示
在這裡插入圖片描述