<KeyFrameSet>
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
為動畫期間的觀看指定位置和屬性
序列根據預設,動作會從初始狀態移至結束狀態。
使用 <KeyFrameSet>
即可建構更複雜的動作。
<KeyFrameSet>
包含
<KeyPosition>
或
<KeyAttribute>
節點。這些節點會在
動作的特定時間點
MotionLayout
敬上
流暢地以動畫呈現從起點到每個中繼點的檢視畫面
再前往最終目的地
假設動態序列的初始狀態在
在檢視畫面的左下角,最終狀態則會讓球在顯示
。根據預設,MotionLayout
會平滑地移動球
沿著對角線逐漸變透明,直到它消失為止
延遲時間計算的是
資訊封包從來源傳輸至目的地的時間您可以使用 <KeyFrameSet>
變更這項行為。
例如,您可以讓球垂直移動到左上角
仍完全不透明,然後水平移動到右上角
。方法是建立 <KeyFrameSet>
並
在其中加入 <KeyPosition>
和 <KeyAttribute>
<KeyPosition>
會指定球的中繼位置,而 <KeyAttribute>
指定球在移動的中間點保持不透明。
語法
<KeyFrameSet>
[ <KeyPosition/>... ]
[ <KeyAttribute/>...]
</KeyFrameSet>
包含於
<Transition>
包含
<KeyPosition>
- 指定檢視畫面在動作序列中特定時間點的位置。
<KeyAttribute>
- 指定動作序列中特定時間點的檢視畫面屬性。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# <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."]]