<KeyFrameSet>
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
指定运动过程中视图的位置和属性
序列。默认情况下,动作会从初始状态进入结束状态。
通过使用 <KeyFrameSet>
,您可以构建更复杂的运动。
<KeyFrameSet>
包含
<KeyPosition>
或
<KeyAttribute>
节点。这些节点用于指定目标视图在
动画中某个特定的点
MotionLayout
从起点到每个中间点平稳地以动画方式呈现视图
然后再前往最终的目的地
假设运动序列的初始状态下,
而最终状态为透明的
。默认情况下,MotionLayout
会平稳移动球
逐渐变透明,直至消失
到达目的地。您可以使用 <KeyFrameSet>
更改此行为。
例如,您可以让球垂直移动到左上角
同时保持完全不透明,再水平移动到右上角
角落里的图标。为此,您可以创建一个 <KeyFrameSet>
并
在其中添加 <KeyPosition>
和 <KeyAttribute>
。<KeyPosition>
用于指定球的中间位置,而 <KeyAttribute>
指定球在运动的中点处保持不透明。
语法
<KeyFrameSet>
[ <KeyPosition/>... ]
[ <KeyAttribute/>...]
</KeyFrameSet>
包含于
<Transition>
包含
<KeyPosition>
- 指定视图在运动序列中特定时刻的位置。
<KeyAttribute>
- 指定运动序列中特定时刻的视图属性。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# <KeyFrameSet>\n\nSpecifies location and attributes for views over the course of the motion\nsequence. By default, motion proceeds from the initial state to the end state.\nBy using `\u003cKeyFrameSet\u003e`, you can build more complex motions.\n\nThe `\u003cKeyFrameSet\u003e` contains\n[`\u003cKeyPosition\u003e`](/training/constraint-layout/motionlayout/ref/keyposition) or\n[`\u003cKeyAttribute\u003e`](/training/constraint-layout/motionlayout/ref/keyattribute)\nnodes. These nodes specify the position or attributes of a target view at a\nspecific point in the motion.\n[`MotionLayout`](/reference/androidx/constraintlayout/motion/widget/MotionLayout)\nsmoothly animates the view from the starting point to each intermediate point\nand then to the final destination.\n\nSuppose the initial state of the motion sequence has an opaque ball in the\nlower-left corner of the view, and the final state makes the ball transparent in\nthe upper-right corner. By default, the `MotionLayout` moves the ball smoothly\nin a diagonal line, gradually becoming transparent until it vanishes when it\nreaches its destination. By using `\u003cKeyFrameSet\u003e`, you can change this behavior.\nFor example, you can make the ball move vertically to the upper-left corner\nwhile remaining entirely opaque, then move horizontally to the upper-right\ncorner while fading out. You can do this by creating a `\u003cKeyFrameSet\u003e` and\nadding a `\u003cKeyPosition\u003e` and `\u003cKeyAttribute\u003e` inside it. The `\u003cKeyPosition\u003e`\nspecifies the intermediate location of the ball, and the `\u003cKeyAttribute\u003e`\nspecifies that the ball remains opaque at the midpoint of the motion.\n\nSyntax\n------\n\n```xml\n\u003cKeyFrameSet\u003e\n [ \u003cKeyPosition/\u003e... ]\n [ \u003cKeyAttribute/\u003e...]\n\u003c/KeyFrameSet\u003e\n```\n\nContained in\n------------\n\n[`\u003cTransition\u003e`](/training/constraint-layout/motionlayout/ref/transition)\n\nContains\n--------\n\n[`\u003cKeyPosition\u003e`](/training/constraint-layout/motionlayout/ref/keyposition)\n: Specifies a view's position at a specific moment during the motion sequence.\n\n[`\u003cKeyAttribute\u003e`](/training/constraint-layout/motionlayout/ref/keyattribute)\n: Specifies view attributes at a specific moment during the motion sequence."]]