<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 UTC
[[["เข้าใจง่าย","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 UTC"],[],[],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."]]