2023-12-29|閱讀時間 ‧ 約 26 分鐘

ConstraintLayout 約束佈局:探討 Chains 鏈結屬性如何使用

【Android 入門指南】系列文章目錄:https://bit.ly/3TFgCzu
Android 線上課程教學影片:https://bit.ly/433Offj

課程摘要

本課程學習如何使用 ConstraintLayout 約束佈局中的 Chains 鏈結屬性。

教學影片

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

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

程式碼範例

範例名稱:ConstraintLayout 約束佈局:探討 Chains 鏈結屬性如何使用
作者:HKT (侯光燦)
授權範圍:使用時必須註明出處且不得為商業目的之使用
範例下載點:點我下載

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">

<Button
android:id="@+id/btn_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btn_b" />

<Button
android:id="@+id/btn_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B"
app:layout_constraintTop_toTopOf="@+id/btn_a"
app:layout_constraintEnd_toStartOf="@+id/btn_c"
app:layout_constraintStart_toEndOf="@+id/btn_a"/>

<Button
android:id="@+id/btn_c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/btn_b"
app:layout_constraintTop_toTopOf="@+id/btn_a" />
</androidx.constraintlayout.widget.ConstraintLayout>
分享至
成為作者繼續創作的動力吧!
從 Google News 追蹤更多 vocus 的最新精選內容從 Google News 追蹤更多 vocus 的最新精選內容

作者的相關文章

HKT實驗室 的其他內容

你可能也想看

發表回應

成為會員 後即可發表留言
© 2024 vocus All rights reserved.