在 Wear OS 上构建基于视图的界面
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
试试 Compose 方式
Jetpack Compose on Wear OS 是适用于 Wear OS 的推荐界面工具包。
Android Jetpack 包含 Wear OS 界面库。Wear OS 界面库包含以下类:
如需查看完整列表,请参阅版本说明。
添加 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"
}
从 Wear OS 界面库软件包导入类
如需使用 Wear OS 界面库中的某个类,请从 androidx.wear.widget
软件包导入该类。
在布局文件中使用正确的元素名称
在布局文件中,请使用与 Wear OS 界面库对应的完全限定名称。
例如,如需使用 Wear OS 界面库中的
DismissibleFrameLayout
类,您可以在布局文件中指定以下内容:
<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 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],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```"]]