2021年2月2日 星期二

Android Studio - Linear Layout 線性版面佈局(十一)

Android Studio - Linear Layout 線性版面佈局(十一):

Linear Layout(線性版面佈局)是 Android 中較為常用的佈局方式,使用 <linearlayout> </linearlayout> 標籤。線性佈局主要有兩種形式,一種是水平線性佈局(Horizontal Orientation),一種是垂直線性佈局(Vertical Orientation)。需要注意的是 Android 的線性佈局不會換行,當元件一個挨著一個地排列到頭之後,剩下的元件將不會被顯示出來。

Android Studio Linear Layout 線性版面佈局
  • 操作系統:Windows 7 64-bit 版本 開發環境:Android Studio 4.0.1 版本
  • Gradle 版本:6.1.1
  • 手機測試版本:API 19
  • 原程式:C:\Development\Development_Android\Android_Project\ Layout - LineraLayout
  • 程式:C:\Development\Development_Android\Android_Project\ Layout - LineraLayout
Linear Layout - layout/activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:background="#ff0"

    android:orientation="vertical" >

 

    <Button

        android:id="@+id/Button15"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_gravity="left"

        android:text="靠左" />

 

    <Button

        android:id="@+id/Button02"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginLeft="30dp"

        android:text="離左邊界30dp" />

 

    <Button

        android:id="@+id/Button01"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_gravity="right"

        android:text="靠右" />

 

    <Button

        android:id="@+id/Button03"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_gravity="center_horizontal"

        android:text="置中" />

 

    <TextView

        android:layout_width="wrap_content"

        android:layout_height="120dp"

        android:layout_gravity="left"

        android:background="#FF7428"

        android:gravity="center"

        android:text="(*^__^*) 嘻嘻……" />

 

    <LinearLayout

        android:layout_width="wrap_content"

        android:layout_height="match_parent"

        android:background="#cc0"

        android:orientation="horizontal" >

 

        <Button

            android:id="@+id/Button14"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="Button14" />

 

        <Button

            android:id="@+id/button2"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="Button2" />

 

        <Button

            android:id="@+id/Button11"

            android:layout_width="wrap_content"

            android:layout_height="80dp"

            android:text="以我為列高" />

 

        <LinearLayout

            android:layout_width="100dp"

            android:layout_height="match_parent"

            android:background="#f0f"

            android:orientation="vertical" >

 

            <Button

                android:id="@+id/button1"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="Button15" />

 

            <Button

                android:id="@+id/Button16"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="Button16" />

 

            <Button

                android:id="@+id/Button17"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:text="Button17" />

        </LinearLayout>

    </LinearLayout>

 

</LinearLayout>


Linear Layout 線性版面佈局屬性
Linear Layout 線性版面佈局主要屬性:

XML attributes

Description

android:baselineAligned

When set to false, prevents the layout from aligning its children's baselines. 

android:baselineAlignedChildIndex

When a linear layout is part of another layout that is baseline aligned, it can specify which of its children to baseline align to (that is, which child TextView). 

android:divider

Drawable to use as a vertical divider between buttons. 

android:gravity

Specifies how an object should position its content, on both the X and Y axes, within its own bounds. 

android:measureWithLargestChild

When set to true, all children with a weight will be considered having the minimum size of the largest child. 

android:orientation

Should the layout be a column or a row? Use "horizontal" for a row, "vertical" for a column. 

android:weightSum

Defines the maximum weight sum. 

android:layout_gravity

Gravity specifies how a component should be placed in its group of cells

android:layout_weight

Indicates how much of the extra space in the LinearLayout is allocated to the view associated with these LayoutParams

android:layout_margin

Specifies extra space on the left, top, right and bottom sides of this view. 

android:layout_marginBottom

Specifies extra space on the bottom side of this view. 

android:layout_marginEnd

Specifies extra space on the end side of this view. 

android:layout_marginHorizontal

Specifies extra space on the left and right sides of this view. 

android:layout_marginLeft

Specifies extra space on the left side of this view. 

android:layout_marginRight

Specifies extra space on the right side of this view. 

android:layout_marginStart

Specifies extra space on the start side of this view. 

android:layout_marginTop

Specifies extra space on the top side of this view. 

android:layout_marginVertical

Specifies extra space on the top and bottom sides of this view. 


2021年 2月 2日(Tue)天氣報告
氣溫:32.0°F / 0.0°C @ 08:00
風速:每小時 26 公里
相對濕度:百分之 85%
天氣:多雲

沒有留言:

張貼留言