代表時間
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
錶面的首要任務是顯示時間,而錶面格式可讓您使用 AnalogClock
和 DigitalClock
元素建立指針和數位時鐘。
數位時鐘
您可以使用錶面 Scene
中的 DigitalClock
和 TimeText
元素定義基本數位時鐘:
<DigitalClock x="100" y="100" width="200" height="50">
<TimeText x="0" y="0" width="200" height="50" format="hh:mm">
<Font family="SYNC_TO_DEVICE" size="16" />
</TimeText>
</DigitalClock>
format
屬性可讓您控制如何使用小時、分鐘和秒數組合來表示時間。具體選項會因所使用的錶面格式版本而異;第 2 版會擴充此處的選項。
在上述範例中,「Font」已設為使用系統字型。
您也可以顯示世界其他地區的時間,例如世界時鐘。您可以透過 Localization
元素達成此目標:
<DigitalClock x="100" y="100" width="200" height="50">
<Localization timeZone="Europe/London" />
...
</DigitalClock>
類比時鐘
如要建立類比時鐘,請使用 AnalogClock
元素。每個 HourHand, MinuteHand
和 SecondHand
子元素都會指定應在算繪作業中使用的資源:
<AnalogClock x="0" y="0" width="200" height="200">
<HourHand resource="hour_hand" ... />
<MinuteHand resource="minute_hand" />
<SecondHand resource="second_hand" />
<!-- Optionally add a Tick or Sweep child element to define SecondHand behavior -->
</AnalogClock>
指定樞紐點
每個小時、分鐘和秒資源都會隨著時間推移而旋轉,但請務必指定每個資源應以何處為基準點旋轉。
在某些情況下,樞紐點並非位於手掌底部,而是水平居中。應指定為 <HourHand …
pivotY="(pivot_ratio)" />
,其中:
$$
pivot\_ratio = \frac{pivot\_height}{full\_height}
$$
為手錶指針著色
為了讓使用者自訂錶面的外觀,通常會提供可設定的指針顏色。
如要達成這一點,您可以透過各個手錶的 tintColor
分別為各個手錶著色,或是透過 AnalogClock
為所有手錶著色。
除了讓使用者套用特定色調,您也可以為 tintColor
提供設定選項,讓使用者選擇下列項目:
<AnalogClock ... tintColor="[CONFIGURATION.handColors.0]" />
投射陰影
如要呈現逼真的錶針效果,請在每個錶針後方使用投影效果,以營造出深度感。如要實現這一效果,請使用兩個手型,並將其中一個手型置於另一個手型後方,為陰影提供個別資源:
<!-- Offset the shadow by 5 units in both directions -->
<HourHand resource="hour_hand_shadow" ... x="105" y="105">
<!-- ... -->
<HourHand resource="hour_hand" ... x="100" y="100">
臉部裝飾
類比錶面通常會在錶面周圍加上裝飾,用來顯示小時或分鐘。如要做到這一點,有兩種方法:
請附上全螢幕背景圖片,其中包含預先繪製的錶面。參閱處理圖片相關說明。
<PartImage x="0" y="0" width="450" height="450" ...>
<Image resource="watch_face_dial" />
</PartImage>
繪製個別裝飾,並使用旋轉功能將裝飾置於臉部周圍。
<Group ... >
<!-- Content for the "12" marker -->
</Group>
<Group pivotX="..." pivotY="..." angle="30">
<!-- Content for the "1" marker -->
</Group>
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# Represent the time\n\nThe primary job of a watch face is to show the time, and the Watch Face Format\nlets you create both analog and digital clocks using the\n[`AnalogClock`](/training/wearables/wff/clock/analog-clock) and [`DigitalClock`](/training/wearables/wff/clock/digital-clock) elements.\n\n### Digital clocks\n\nA basic digital clock can be defined using the `DigitalClock` and\n[`TimeText`](/training/wearables/wff/clock/time-text) element within your watch face `Scene`: \n\n \u003cDigitalClock x=\"100\" y=\"100\" width=\"200\" height=\"50\"\u003e\n \u003cTimeText x=\"0\" y=\"0\" width=\"200\" height=\"50\" format=\"hh:mm\"\u003e\n \u003cFont family=\"SYNC_TO_DEVICE\" size=\"16\" /\u003e\n \u003c/TimeText\u003e\n \u003c/DigitalClock\u003e\n\nThe `format` attribute lets you control how the time is represented using\na combination of hours, minutes, and seconds. The exact options differ depending\non the version of Watch Face Format being used; version 2 expands the options\nhere.\n\nIn the preceding example, [Font](/training/wearables/wff/group/part/text/font) is set to use the system font.\n\nIt can also be useful to show the time for other locations in the world, for\nexample a *world clock* . This can be achieved through the [`Localization`](/training/wearables/wff/common/localization)\nelement: \n\n \u003cDigitalClock x=\"100\" y=\"100\" width=\"200\" height=\"50\"\u003e\n \u003cLocalization timeZone=\"Europe/London\" /\u003e\n ...\n \u003c/DigitalClock\u003e\n\n### Analog clocks\n\nTo create an analog clock, use the [`AnalogClock`](/training/wearables/wff/clock/analog-clock) element. Each of the\n`HourHand, MinuteHand`, and `SecondHand` child elements specifies the resource\nthat should be used in the rendering: \n\n \u003cAnalogClock x=\"0\" y=\"0\" width=\"200\" height=\"200\"\u003e\n \u003cHourHand resource=\"hour_hand\" ... /\u003e\n \u003cMinuteHand resource=\"minute_hand\" /\u003e\n \u003cSecondHand resource=\"second_hand\" /\u003e\n \u003c!-- Optionally add a Tick or Sweep child element to define SecondHand behavior --\u003e\n \u003c/AnalogClock\u003e\n\n#### Specify the pivot point\n\nEach of the hour, minute, and second resources are rotated as time advances,\nbut it is important to specify the correct point around which each should pivot.\n\nIn some situations, the pivot point is not quite at the bottom of the hand, and\nis centered horizontally. This should be specified as `\u003cHourHand ...\npivotY=\"(pivot_ratio)\" /\u003e` where: \n$$ pivot\\\\_ratio = \\\\frac{pivot\\\\_height}{full\\\\_height} $$\n\n#### Color the watch hands\n\nTo allow the user to customize the appearance of the watch face, it is common to\nhave a configurable color for the watch hands.\n\nA way to achieve this is through the `tintColor` on each of the hands to\nseparately tint each hand, or on `AnalogClock`, to tint all hands the same\ncolor.\n\nIn addition to enabling users to tint specific colors, you can supply a\nconfiguration option to `tintColor` to allow the user to choose: \n\n \u003cAnalogClock ... tintColor=\"[CONFIGURATION.handColors.0]\" /\u003e\n\n#### Drop shadow\n\nFor a realistic watch hand effect, using a drop shadow behind each hand can give\nthe appearance of depth. To achieve this, use two of each hand type, offsetting\none behind the other, supplying a separate resource for the shadow: \n\n \u003c!-- Offset the shadow by 5 units in both directions --\u003e\n \u003cHourHand resource=\"hour_hand_shadow\" ... x=\"105\" y=\"105\"\u003e\n \u003c!-- ... --\u003e\n \u003cHourHand resource=\"hour_hand\" ... x=\"100\" y=\"100\"\u003e\n\n#### Face decorations\n\nAnalog watch faces often have decorations around the face showing the hours or\nminutes. To achieve this, there are two approaches:\n\n1. Include a full-screen background image, which contains your predrawn watch\n face. [See working with images](/training/wearables/wff/images).\n\n \u003cPartImage x=\"0\" y=\"0\" width=\"450\" height=\"450\" ...\u003e\n \u003cImage resource=\"watch_face_dial\" /\u003e\n \u003c/PartImage\u003e\n\n2. Draw separate decorations and position them around the face using rotations.\n\n \u003cGroup ... \u003e\n \u003c!-- Content for the \"12\" marker --\u003e\n \u003c/Group\u003e\n \u003cGroup pivotX=\"...\" pivotY=\"...\" angle=\"30\"\u003e\n \u003c!-- Content for the \"1\" marker --\u003e\n \u003c/Group\u003e"]]