處理不同的手錶形狀
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
試試 Compose 的方式
建議您使用 Wear OS 版 Jetpack Compose,這是 Wear OS 的推薦 UI 工具包。
Wear OS 應用程式使用與其他 Android 裝置相同的版面配置技巧,但必須根據手錶專屬的限制來設計。
注意:請勿將行動應用程式的功能和 UI 原封不動轉移至 Wear OS,這個方法不太可能提供良好的使用者體驗。
如果您是針對矩形手持裝置設計應用程式,那麼螢幕角落的內容可能會在圓形手錶上遭到裁切。如果您使用可捲動的垂直清單,那麼受到的影響可能會較小,因為使用者能夠捲動畫面將內容置中。不過,如果是單螢幕畫面,可能會導致使用者體驗不佳。
如果您為版面配置使用下列設定,文字會無法在圓形螢幕的裝置上正確顯示:
<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">
<TextView
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="@string/very_long_hello_world"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
為解決這個問題,請使用支援圓形裝置的 Wear OS UI 程式庫中的版面配置。
如要進一步瞭解如何設計應用程式,請參閱 Wear OS 設計指南。
使用 BoxInsetLayout
圖 2. 圓形螢幕上的視窗插邊。
您可以使用 Wear OS UI 程式庫中的 BoxInsetLayout
類別,定義圓形螢幕適用的版面配置。這個類別可輕鬆將畫面置中對齊或靠近螢幕邊緣。
在套用所需的視窗插邊後,BoxInsetLayout
可將子檢視區塊自動顯示在圓形螢幕上,如圖 2 中的灰色正方形所示。為了要在這個區域中顯示,子檢視區塊會使用下列值指定 layout_boxedEdges
屬性:
top
、bottom
、left
和 right
的組合。例如,"left|top"
值會將子項的左側和頂端邊緣置於圖 2 的灰色正方形中。
"all"
值會將所有子項內容置於圖 2 的灰色正方形中。這是內含 ConstraintLayout
最常見的做法。
圖 2 所示的版面配置使用 <BoxInsetLayout>
元素,適用於圓形螢幕:
<androidx.wear.widget.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:padding="15dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
app:layout_boxedEdges="all">
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/sometext"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:background="@android:color/transparent"
android:layout_height="50dp"
android:layout_width="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:src="@drawable/cancel" />
<ImageButton
android:background="@android:color/transparent"
android:layout_height="50dp"
android:layout_width="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:src="@drawable/ok" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.wear.widget.BoxInsetLayout>
請注意版面配置中以粗體標示的部分:
-
android:padding="15dp"
此行會將邊框間距指派給 <BoxInsetLayout>
元素。
-
android:padding="5dp"
此行會將邊框間距指派給內部 ConstraintLayout
元素。
-
app:layout_boxedEdges="all"
此行可確保 ConstraintLayout
元素及其子項位於圓形螢幕上視窗插邊所定義的區域內。
使用曲線版面配置
Wear OS UI 程式庫中的
WearableRecyclerView
類別可讓您選擇採用曲線版面配置,並針對圓形螢幕進行最佳化調整。如要為應用程式中的可捲動清單啟用曲線版面配置,請參閱「在 Wear OS 上建立清單」。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[],[],null,["# Handle different watch shapes\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\nApps on Wear OS use the same layout techniques as other Android devices\nbut need to be designed with watch-specific constraints.\n\n\n**Note:** Don't port the exact functionality and UI from a mobile app to Wear OS and expect\na good user experience.\n\n\nIf you design your app for a rectangular handheld device, content near the corners of the screen\nmight be cropped on round watches. If you are using a scrollable vertical list, this is less of\nan issue, as the user can scroll to center the content. However, for single screens, it can\nprovide a bad user experience.\n\n\nIf you use the following settings for your layout, text displays incorrectly on devices\nwith round screens: \n\n```xml\n\u003candroidx.constraintlayout.widget.ConstraintLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n xmlns:tools=\"http://schemas.android.com/tools\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\u003e\n\n \u003cTextView\n android:id=\"@+id/text\"\n android:layout_width=\"0dp\"\n android:layout_height=\"0dp\"\n android:text=\"@string/very_long_hello_world\"\n app:layout_constraintBottom_toBottomOf=\"parent\"\n app:layout_constraintEnd_toEndOf=\"parent\"\n app:layout_constraintStart_toStartOf=\"parent\"\n app:layout_constraintTop_toTopOf=\"parent\" /\u003e\n\n\u003c/androidx.constraintlayout.widget.ConstraintLayout\u003e\n```\n\n\nTo solve this problem, use layouts in the [Wear OS UI Library](/training/wearables/views) that support round devices.\n\n- You can use a [`BoxInsetLayout`](/reference/androidx/wear/widget/BoxInsetLayout) to prevent views from being cropped near the edges of round screens.\n- You can use a [WearableRecyclerView](/reference/androidx/wear/widget/WearableRecyclerView) to create a curved layout when you want to display and manipulate a vertical list of items optimized for round screens.\n\n\nFor more information about designing apps, read the\n[Wear OS design guidelines](/training/wearables/design).\n\nUse a BoxInsetLayout\n--------------------\n\n\n**Figure 2.** Window insets on a round screen.\n\n\nThe [`BoxInsetLayout`](/reference/androidx/wear/widget/BoxInsetLayout) class in the Wear OS UI Library lets\nyou define a layout that works for round screens. This class lets you\neasily align views on the center or near the edges of the screen.\n\n\nThe gray square in figure 2 shows the area where the `BoxInsetLayout`\ncan automatically place its child views on round screens after applying\nthe required window insets. To be displayed inside this area, child\nviews specify the `layout_boxedEdges` attribute with the following values:\n\n- A combination of `top`, `bottom`, `left`, and `right`. For example, a `\"left|top\"` value positions the child's left and top edges inside the gray square in figure 2.\n- The `\"all\"` value positions all the child's content inside the gray square in figure 2. This is the most common approach with a [`ConstraintLayout`](/reference/androidx/constraintlayout/widget/ConstraintLayout) inside.\n\n\nThe layout shown in figure 2 uses the `\u003cBoxInsetLayout\u003e`\nelement and works on round screens: \n\n```xml\n\u003candroidx.wear.widget.BoxInsetLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n android:layout_height=\"match_parent\"\n android:layout_width=\"match_parent\"\n android:padding=\"15dp\"\u003e\n\n \u003candroidx.constraintlayout.widget.ConstraintLayout\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\n android:padding=\"5dp\"\n app:layout_boxedEdges=\"all\"\u003e\n\n \u003cTextView\n android:layout_height=\"wrap_content\"\n android:layout_width=\"match_parent\"\n android:text=\"@string/sometext\"\n android:textAlignment=\"center\"\n app:layout_constraintEnd_toEndOf=\"parent\"\n app:layout_constraintStart_toStartOf=\"parent\"\n app:layout_constraintTop_toTopOf=\"parent\" /\u003e\n\n \u003cImageButton\n android:background=\"@android:color/transparent\"\n android:layout_height=\"50dp\"\n android:layout_width=\"50dp\"\n app:layout_constraintBottom_toBottomOf=\"parent\"\n app:layout_constraintStart_toStartOf=\"parent\"\n android:src=\"@drawable/cancel\" /\u003e\n\n \u003cImageButton\n android:background=\"@android:color/transparent\"\n android:layout_height=\"50dp\"\n android:layout_width=\"50dp\"\n app:layout_constraintBottom_toBottomOf=\"parent\"\n app:layout_constraintEnd_toEndOf=\"parent\"\n android:src=\"@drawable/ok\" /\u003e\n\n \u003c/androidx.constraintlayout.widget.ConstraintLayout\u003e\n\n\u003c/androidx.wear.widget.BoxInsetLayout\u003e\n```\n\n\nNotice the parts of the layout marked in bold:\n\n-\n `android:padding=\"15dp\"`\n\n\n This line assigns padding to the `\u003cBoxInsetLayout\u003e`\n element.\n-\n `android:padding=\"5dp\"`\n\n\n This line assigns padding to the inner `ConstraintLayout` element.\n-\n `app:layout_boxedEdges=\"all\"`\n\n\n This line ensures that the `ConstraintLayout` element\n and its children are boxed inside the area defined by the window\n insets on round screens.\n\nUse a curved layout\n-------------------\n\nThe [WearableRecyclerView](/reference/androidx/wear/widget/WearableRecyclerView) class in the Wear OS UI Library\nlets you opt-in to a curved layout optimized for round screens.\nTo enable a curved layout for scrollable lists in your\napp, see [Create lists on Wear OS](/training/wearables/ui/lists#creating)."]]