<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 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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."]]