สร้าง UI ที่อิงตามการดูใน Wear OS
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ลองใช้วิธีเขียน
Jetpack Compose ใน Wear OS เป็นชุดเครื่องมือ UI ที่แนะนำสำหรับ Wear OS
Android Jetpack มีไลบรารี UI ของ Wear OS
ไลบรารี UI ของ Wear OS มีคลาสต่อไปนี้
โปรดอ่านบันทึกประจำรุ่นเพื่อดูรายการทั้งหมด
เพิ่มการพึ่งพาไลบรารี UI ของ Wear OS
หากต้องการเริ่มสร้างแอป ให้สร้างโปรเจ็กต์สำหรับ Wear OS โดยเฉพาะ จากนั้นเพิ่มการพึ่งพาต่อไปนี้ลงในไฟล์ build.gradle
ของแอป
dependencies {
...
// Standard Wear OS libraries
implementation "androidx.wear:wear:1.2.0"
// includes support for wearable specific inputs
implementation "androidx.wear:wear-input:1.1.0"
}
นำเข้าชั้นเรียนจากแพ็กเกจไลบรารี UI ของ Wear OS
หากต้องการใช้คลาสจากไลบรารี UI ของ Wear OS ให้นำเข้าจากแพ็กเกจ androidx.wear.widget
ใช้ชื่อองค์ประกอบที่ถูกต้องในไฟล์เลย์เอาต์
ในไฟล์เลย์เอาต์ ให้ใช้ชื่อที่สมบูรณ์ซึ่งสอดคล้องกับไลบรารี UI ของ Wear OS
เช่น หากต้องการใช้คลาส
DismissibleFrameLayout
จากไลบรารี UI ของ Wear OS คุณอาจระบุข้อมูลต่อไปนี้ในไฟล์เลย์เอาต์
<androidx.wear.widget.DismissibleFrameLayout
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:id="@+id/swipe_dismiss_root" >
<TextView
android:id="@+id/test_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Swipe the screen to dismiss me." />
</androidx.wear.widget.DismissibleFrameLayout>
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# Build View-based UIs on Wear OS\n\nTry the Compose way \nJetpack Compose on Wear OS is the recommended UI toolkit for Wear OS. \n[Try Compose on Wear OS →](/training/wearables/compose) \n\n\n[Android Jetpack](/jetpack/androidx) includes the Wear OS UI Library.\nThe Wear OS UI library includes the following classes:\n\n- [CurvedTextView](/reference/kotlin/androidx/wear/widget/CurvedTextView): a component for easily writing text that follows the curvature of the largest circle that can be inscribed in the view.\n- [DismissibleFrameLayout](/reference/androidx/wear/widget/DismissibleFrameLayout): a layout that lets the user dismiss any view by pressing the back button or swiping on the screen from left to right. Wear OS users expect left-to-right swiping for the back action.\n- [WearableRecyclerView](/reference/androidx/wear/widget/WearableRecyclerView): a view that provides basic offsetting logic for updating child layouts using a [WearableLinearLayoutManager](/reference/androidx/wear/widget/WearableLinearLayoutManager).\n- [AmbientModeSupport](/reference/androidx/wear/ambient/AmbientModeSupport): a class used with the [AmbientModeSupport.AmbientCallbackProvider](/reference/androidx/wear/ambient/AmbientModeSupport.AmbientCallbackProvider) interface to provide support for ambient mode.\n\n\nFor a full list, read the [release notes](/jetpack/androidx/releases/wear).\n\nAdd a dependency on the Wear OS UI Library\n------------------------------------------\n\n\nTo start creating apps, create a Wear-OS-specific project. Then add the following dependencies\nto your app's `build.gradle` file: \n\n```groovy\ndependencies {\n ...\n // Standard Wear OS libraries\n implementation \"androidx.wear:wear:1.2.0\"\n // includes support for wearable specific inputs\n implementation \"androidx.wear:wear-input:1.1.0\"\n}\n```\n\nImport classes from the Wear OS UI Library package\n--------------------------------------------------\n\n\nTo use a class from the Wear OS UI Library, import it from the\n`androidx.wear.widget` package.\n\nUse the right element names in layout files\n-------------------------------------------\n\n\nIn layout files, use fully qualified names that correspond to the Wear OS UI\nLibrary.\n\n\nFor example, to use the\n[DismissibleFrameLayout](/reference/androidx/wear/widget/DismissibleFrameLayout) class from the Wear OS UI Library, you could specify\nthe following in a layout file: \n\n```xml\n\u003candroidx.wear.widget.DismissibleFrameLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:tools=\"http://schemas.android.com/tools\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\n android:id=\"@+id/swipe_dismiss_root\" \u003e\n\n \u003cTextView\n android:id=\"@+id/test_content\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\n android:gravity=\"center\"\n android:text=\"Swipe the screen to dismiss me.\" /\u003e\n\u003c/androidx.wear.widget.DismissibleFrameLayout\u003e\n```"]]