LinearLayout 線性佈局 orientation 排列方向屬性介紹

2023/12/29閱讀時間約 5 分鐘
【Android 入門指南】系列文章目錄:https://bit.ly/3TFgCzu
Android 線上課程教學影片:https://bit.ly/433Offj

課程摘要

本課程學習如何使用 LinearLayout 線性佈局中的orientation 排列方向屬性。

教學影片

若您無法順利觀看教學影片,請先登入您的 YouTube 帳號,然後點擊以下連結加入我們的頻道會員:

  • 一般會員:成為一般會員後,您將能夠觀看我們所提供的一般會員專屬線上課程。
  • 精實會員:成為精實會員後,您將能夠觀看我們所提供的精實會員專屬線上課程。

線性佈局 LinearLayout

LinearLayout 佈局容器在 Android 經常使用,可以讓你將元件放在這個容器中呈現垂直或水平的線性排列。

raw-image

垂直方向排列 orientation=“vertical” 實作範例

程式碼範例

範例名稱:LinearLayout 線性佈局 orientation 垂直方向排列


作者:HKT (侯光燦)


授權範圍:使用時必須註明出處且不得為商業目的之使用


範例下載點:點我下載


raw-image

activity_main.xml

<?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"
android:background="#e6e6e6"
android:gravity="center"
android:orientation="vertical">

<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:text="元件二" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="元件三" />

</LinearLayout>

水平方向排列 orientation=“horizontal” 實作範例

程式碼範例

範例名稱:LinearLayout 線性佈局 orientation 水平方向排列
作者:HKT (侯光燦)
授權範圍:使用時必須註明出處且不得為商業目的之使用
範例下載點:點我下載


raw-image

activity_main.xml

<?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"
android:background="#e6e6e6"
android:gravity="center"
android:orientation="horizontal">

<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:text="元件二" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="元件三" />

</LinearLayout>
3會員
176內容數
本指南將以清晰易懂的方式介紹基礎概念,讓你能夠快速上手,輕鬆踏上學習 Kotlin 的旅程 透過簡單易懂的方式,讓你將能夠在短時間內建立起對 Kotlin 的基本了解,並開始實際應用於你的專案之中。不論你是想要進入 Android 開發領域或者只是想探索新的程式語言,這份指南都會成為你學習 Kotlin 的理想起點。
留言0
查看全部
發表第一個留言支持創作者!