條件


此元素可提供比較邏輯,以便有條件地啟用子項元素的顯示、動畫和事件處理功能。

這項元素已在 Wear OS 4 推出。

語法

<Condition>
    <!-- The "Expressions" element is required. -->
    <Expressions>
        <Expression name="unique-name">
            <!-- Arithmetic expression goes here. -->
        </Expression>
        <!-- Other expressions go here. -->
    </Expressions>
    <!-- The "expression" attribute is required. -->
    <Compare expression="expression-name">
        <!-- ONE of the following only: -->
        <Group ... />
        <PartText ... />
        <PartImage ... />
        <PartAnimatedImage ... />
        <PartDraw ... />
        <Condition ... />
        <AnalogClock ... />
        <DigitalClock ... />
    </Compare>
    <!-- The "else" case for when all of the above "Compar e"
         conditions are false. -->
    <Default>
        <!-- ONE of the following only: -->
        <Group ... />
        <PartText ... />
        <PartImage ... />
        <PartAnimatedImage ... />
        <PartDraw ... />
        <Condition ... />
        <AnalogClock ... />
        <DigitalClock ... />
    </Default>
</Condition>

內部元素

Condition 元素包含下列內部元素:

Expressions

這可用來定義一組 Expression 元素,這些元素分別都具有 name 屬性和算術運算式。包含 Condition 元素內的 name 不得重複。

Condition 元素至少必須包含一個 Expressions 元素。

Compare

含有單一元素樹狀結構,且只有在具有指定名稱的運算式評估為 true 或非零值時,該結構才會顯示、呈現動畫效果並能接收事件。name 屬性必須與 Expression 元素的 name 屬性相符,其中 Expression 元素會用於 Condition 元素的其他位置。

Default

含有單一元素樹狀結構,且只有在所有 Compare 元素群組皆未啟動時,該結構才會顯示、呈現動畫效果並能接收事件。