应用布局
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
试试 Compose 方式
Jetpack Compose on Wear OS 是适用于 Wear OS 的推荐界面工具包。
在您了解如何处理不同的手表形状之后,需要确定您要使用的 surface。
常见的应用布局包括:
-
单屏(最简单):界面元素可全部显示在一个屏幕中,无需滚动。
-
垂直容器(最常见):内容溢出到屏幕的可见部分之外(在滚动后可以看到)。
-
其他方案:列表、分页或 2D 平移。
以下部分将介绍这些布局类型。如果您需要多个屏幕,可以结合使用不同的布局类型。
注意:对于 activity,请从 ComponentActivity
继承;如果您使用的是 fragment,则从 FragmentActivity
继承。其他 activity 类型使用了移动设备专用的界面元素,Wear OS 不需要这些元素。
单屏
用户无需滚动,即可在单个屏幕中看到所有元素。这也意味着您只能添加少量元素。
图 1. 单屏布局示例。
单屏适合与 BoxInsetLayout
和 ConstraintLayout
组合使用,用以排列您的元素。
垂直容器
垂直容器是最常见的应用类型。某些内容未显示在屏幕上,但可以通过滚动访问。
图 2 展示了一些完整的应用布局,在这些示例中,手表的圆形屏幕上仅会显示部分内容。在这些示例中,主要内容位于容器的顶部,其他关键用户历程 (CUJ) 和设置位于底部。这是适用于内容布局的最佳实践。
图 2. 垂直容器布局示例。
与单屏应用布局不同,请勿使用 BoxInsetLayout
。请改为在 NestedScrollView
中使用 ConstraintLayout
。在 ConstraintLayout
中放置最适合您的应用的 widget。如此一来,您就可以利用圆形显示屏侧边的额外空间。
图 3. NestedScrollView
内的 ConstraintLayout
中的内容。
和图 3 中的示例一样,请确保垂直容器顶部和底部的内容足够小,与圆形显示屏的顶部和底部相适应。
注意:请尽可能在 XML 中设置 android:scrollbars="vertical"
,从而为 NestedScrollView
添加滚动指示器。这不仅有助于用户确认是否有更多内容,还可以让他们了解目前在所有内容中所处的位置。
应用布局的其他方案
-
列表:使用专为穿戴式设备 surface 优化的
WearableRecyclerView
widget 显示大量数据。如需了解详情,请参阅在 Wear OS 上创建列表。
-
水平分页:对于具有多个同级屏幕的用例,请使用水平滑动。如果您使用水平分页,则必须支持通过在左侧边缘滑动来关闭当前界面。
-
2D 平移:对于地图等用例,用户可以向不同方向拖动平移。如果您的 activity 占据了整个屏幕,请启用滑动即可关闭功能。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[[["易于理解","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"]],["最后更新时间 (UTC):2025-07-26。"],[],[],null,["# App layouts\n\nTry the Compose way \nJetpack Compose on Wear OS is the recommended UI toolkit for Wear OS. \n[Handle different screen sizes using Compose on Wear OS →](/training/wearables/compose/screen-size) \n\n\nAfter you understand how to\n[handle different watch shapes](/training/wearables/apps/layouts),\ndecide which surface you want to use.\n\n\nCommon app layouts include the following:\n\n- Single screen (simplest): UI elements are limited to what is visible at one time without scrolling.\n- Vertical container (most common): content exists beyond the viewable portion of the screen and is accessible by scrolling.\n- Other options: lists, paging, or 2D panning.\n\nThese layout types are described in the sections that follow.\nYou can use a combination of layout types if you need multiple screens.\n\n\n**Note:** For your activity, inherit from either a\n`ComponentActivity` or, if you use fragments, a `FragmentActivity`.\nThe other activity types use mobile-specific UI elements that you don't need for Wear OS.\n\nSingle screen\n-------------\n\n\nThe user sees all elements in a single screen without scrolling. This means you can include only\na small number of elements.\n\n\n**Figure 1.** An example of a single screen layout.\n\n\nSingle screens work well with a\n[BoxInsetLayout](/reference/androidx/wear/widget/BoxInsetLayout)\nin combination with a\n[ConstraintLayout](/reference/androidx/constraintlayout/widget/ConstraintLayout)\nto arrange your elements.\n\nVertical container\n------------------\n\n\nA vertical container is the most common type of app layout. Some content isn't\nvisible on the screen, but it is accessible by scrolling.\n\n\nFigure 2 shows several complete app layouts in which only a portion of the\ncontent can be seen on the circular screen of a watch. In these examples, the main\ncontent is in the top\nportion of the container, and other Critical User Journeys (CUJs) and settings are\nat the bottom. This is a best practice for laying out content.\n\n\n**Figure 2.** Examples of vertical container layouts.\n\nUnlike in a single screen app layout, don't use `BoxInsetLayout`. Instead, use\na `ConstraintLayout` inside a\n[NestedScrollView](/reference/androidx/core/widget/NestedScrollView).\nInside the `ConstraintLayout`, place whatever widgets make the most sense for\nyour app. This lets you take advantage of the extra space on the sides of a circular display.\n\n\n**Figure 3.** Content in a `ConstraintLayout` inside a\n`NestedScrollView`.\n\n\nMake sure the content at the top and bottom of your vertical container is small enough to fit in\nthe top and bottom of a circular display, as in the example in figure 3.\n\n**Note:**\nWhen possible, add a scroll indicator to your `NestedScrollView` by setting\n`android:scrollbars=\"vertical\"` in the XML. This helps users identify that there is\nmore content available and helps them see where they are in relation to all the content.\n\nOther options for app layouts\n-----------------------------\n\n- **Lists** : display large sets of data with the `WearableRecyclerView` widget optimized for Wearable surfaces. For more information, see [Create lists on Wear OS](/training/wearables/apps/lists).\n- **Horizontal paging** : for use cases with multiple sibling screens, use a [horizontal swipe](/guide/navigation/navigation-swipe-view-2). If you use horizontal paging, you must support swipe-to-dismiss for the left edge.\n- **2D Panning** : for use cases like maps, users can [drag to pan](/training/gestures/scale#pan) in different directions. Enable [swipe-to-dismiss](/training/wearables/apps/exit#swipe-to-dismiss) if your activity takes up the entire screen."]]