使用相片打造個人化設定
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
注意:這項功能適用於 Watch Face Format 4 以上版本。
允許使用者選取要加入錶面的相片,有助於為錶面體驗增添個人風格。
「使用圖片」一節已說明如何在錶面上顯示圖片。如果您想讓使用者從一系列預先定義的圖片中選擇,請使用 ListConfiguration
,如「定義使用者設定」一節所示。
如要在錶面中使用使用者可設定的圖片,請使用 <PhotosConfiguration>
元素,例如:
<UserConfigurations>
<PhotosConfiguration id="photoConfig" configType="SINGLE"/>
</UserConfigurations>
configType
可以是 SINGLE
或 MULTIPLE
,表示使用者是否可以在隨播廣告中選取單張圖片或相片集合。
支援單張相片
在單一圖片的情況下,您可以在 PartImage
元素中使用相片,如下所示:
<PartImage ...>
<Photos source="[CONFIGURATION.photoConfig]" defaultImageResource="default_image"/>
</PartImage>
請注意 defaultImageResource
,這是在使用者未在配件中選取相片時顯示的必要屬性。
如果使用者想選取其他相片,則必須使用隨附應用程式,將現有選項替換為其他相片。
支援多張相片
將 PhotosConfiguration
與 configType="MULTIPLE"
搭配使用,可讓錶面顯示相片集合中的相片,使用者可以透過輕觸或在觀看次數達到一定數量後自動切換相片。
<Photos change="ON_VISIBLE TAP" changeAfterEvery="5"
source="[CONFIGURATION.photoConfig]" defaultImageResource="default_image"/>
上例顯示使用 MULTIPLE
時會出現的兩個選項:
change
屬性可讓開發人員指定哪些事件會導致相片輪播可用的圖片。
在上述範例中,TAP
和 ON_VISIBLE
都已指定,表示相片會在使用者輕觸相片時或回應相片可見時變更。
changeAfterEvery
屬性僅適用於 ON_VISIBLE
變更事件,可指定在相片變更前,相片應顯示的次數。舉例來說,您可能會覺得每次使用者喚醒手錶時都變更相片的頻率太高。預設值為 3。
如要進一步瞭解如何使用 PhotosConfiguration
,請參閱 GitHub 上的範例。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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 (世界標準時間)。"],[],[],null,["# Personalize with photos\n\n**Note**: This feature is available on version 4 and higher of Watch Face\nFormat.\n\nAllowing the user to select photos for inclusion on the watch face can help\nbring a personal touch to your watch face experience.\n\nThe [working with images](/training/wearables/wff/images) section already covers how to display images in\nyour watch face. If you want to allow the user to choose from a range of\npredefined images, then use a `ListConfiguration` as shown in the [define user\nconfigurations](/training/wearables/wff/personalization/user-configurations) section.\n\nTo use images in your watch face that the user can configure, use the\n`\u003cPhotosConfiguration\u003e` element, for example: \n\n \u003cUserConfigurations\u003e\n \u003cPhotosConfiguration id=\"photoConfig\" configType=\"SINGLE\"/\u003e\n \u003c/UserConfigurations\u003e\n\nThe `configType` can be either `SINGLE` or `MULTIPLE` indicating whether the\nuser will be able to select a single image within the companion or a collection\nof photos.\n\nSupport a single photo\n----------------------\n\nFor the single image case, the photo can be used within a `PartImage` element as\nfollows: \n\n \u003cPartImage ...\u003e\n \u003cPhotos source=\"[CONFIGURATION.photoConfig]\" defaultImageResource=\"default_image\"/\u003e\n \u003c/PartImage\u003e\n\nNote the `defaultImageResource`, which is shown when the user has not\nselected a photo in the companion and is a required attribute.\n\nIf the user wishes to select a different photo, then they must use the companion\nto replace the existing selection with another.\n\nSupport multiple photos\n-----------------------\n\nUsing `PhotosConfiguration` with `configType=\"MULTIPLE\"` allows the watch face\nto display a photo from a collection, which can be cycled through either through\ntapping or automatically after so many views have taken place. \n\n \u003cPhotos change=\"ON_VISIBLE TAP\" changeAfterEvery=\"5\"\n source=\"[CONFIGURATION.photoConfig]\" defaultImageResource=\"default_image\"/\u003e\n\nThe preceding example shows the two options that are introduced when using\n`MULTIPLE`:\n\n1. The `change` attribute allows the developer to specify what events should cause the photo to cycle through the available images.\n\nIn the preceding example, both `TAP` and `ON_VISIBLE` are specified, meaning\nthat the photo changes in response *either* to a user tapping the photo *or*\nin response to the photo becoming visible.\n\n1. The `changeAfterEvery` attribute applies only to the `ON_VISIBLE` change event, specifing how many times the photo should have become visible before the photo is changed. For example, you may feel that changing the photo every time the user wakes their watch is too frequent. The default value here is 3.\n\nFor more details on working with `PhotosConfiguration`, see the samples on\nGitHub."]]