<MotionScene>
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
動態場景檔案的根元素。<MotionScene>
包含一或多個
<Transition>
元素,每個元素都會定義動態序列的開始和結束狀態,以及
轉換和功能之間的轉換
語法
<MotionScene xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
...
</MotionScene>
必須包含
<Transition>
- 指定要執行的動作序列。如果
<MotionScene>
包含
多個 <Transition>
元素,MotionLayout
會選擇
產生適當的 <Transition>
資源,舉例來說
<MotionScene>
可能有四個 <Transition>
子項,每個子項都有
使用者 <OnSwipe>
往不同方向滑動。當使用者在螢幕上滑動時,
MotionLayout
會使用適當的 <Transition>
做出滑動手勢
往上移動即可
可包含
<ConstraintSet>
- 指定一或多個
<Transition>
的開始或結束狀態
節點。「<MotionLayout>
」不得包含 <ConstraintSet>
子項,因為 <Transition>
可以指向 XML 版面配置,而非
所有限制集
屬性
defaultDuration
- 所有轉換作業的預設時間長度,以毫秒為單位。預設時間長度為
用於未指定時間長度的動作序列。例如:
如果設定
defaultDuration="300"
,所有動作序列預設為 300
毫秒 (如果沒有明確指定時間長度)。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# <MotionScene>\n\nRoot element of a motion scene file. The `\u003cMotionScene\u003e` contains one or more\n[`\u003cTransition\u003e`](/training/constraint-layout/motionlayout/ref/transition)\nelements, each of which defines the start and end state of a motion sequence and\nthe transition between the two.\n\nSyntax\n------\n\n```xml\n\u003cMotionScene xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\u003e\n ...\n\u003c/MotionScene\u003e\n```\n\nMust contain\n------------\n\n`\u003cTransition\u003e`\n: Specifies the motion sequence to perform. If the `\u003cMotionScene\u003e` contains\n multiple `\u003cTransition\u003e` elements, the `MotionLayout` chooses the most\n appropriate `\u003cTransition\u003e` based on the user's interaction. For example, a\n `\u003cMotionScene\u003e` might have four `\u003cTransition\u003e` children, each with an\n [`\u003cOnSwipe\u003e`](/training/constraint-layout/motionlayout/ref/onswipe) for a user\n swipe in a different direction. When the user swipes on the screen, the\n `MotionLayout` uses the appropriate `\u003cTransition\u003e` for a swipe in that\n direction.\n\nCan contain\n-----------\n\n[`\u003cConstraintSet\u003e`](/training/constraint-layout/motionlayout/ref/constraintset)\n: Specifies a beginning or ending state for one or more of the `\u003cTransition\u003e`\n nodes. The `\u003cMotionLayout\u003e` is not permitted to have `\u003cConstraintSet\u003e`\n children, since the `\u003cTransition\u003e` can point to XML layouts instead of\n pointing to constraint sets.\n\nAttributes\n----------\n\n`defaultDuration`\n: Default duration for all transitions in milliseconds. The default duration is\n used for motion sequences that don't specify their own duration. For example,\n if you set `defaultDuration=\"300\"`, all motion sequences default to 300\n milliseconds in length if they don't explicitly specify their own duration."]]