<OnDisabled>
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ระบุการดำเนินการที่จะทำเมื่อผู้ใช้ปัดบนเลย์เอาต์ ความเร็วของ
ลำดับการเคลื่อนไหวและการเคลื่อนไหวของมุมมองเป้าหมายได้รับผลกระทบจาก
ความเร็วและทิศทางการปัดโดยขึ้นอยู่กับขีดจำกัดที่คุณตั้งค่าไว้โดยไม่บังคับ
พารามิเตอร์
อาจมี <OnSwipe>
หลายโหนดสำหรับ <Transition>
เดียว โดยแต่ละโหนด
<OnSwipe>
การระบุทิศทางการเลื่อนและการกระทำที่แตกต่างกันสำหรับ
ทำงานเมื่อผู้ใช้ปัด
วากยสัมพันธ์
<OnSwipe
motion:touchAnchorId="@id/target_view"
motion:touchAnchorSide="side"
[ motion:dragDirection="direction" ]
[ motion:dragScale="scale" ]
[ motion:maxVelocity="maxVelocity" ]
[ motion:maxAcceleration="maxAcceleration" ]
/>
แอตทริบิวต์
motion:touchAnchorId
- มุมมองที่กำลังย้ายโดยการปัด
motion:touchAnchorSide
- ด้านข้างของมุมมองเป้าหมายที่เลื่อนปลายทางอยู่
MotionLayout
เก็บ
ระยะห่างคงที่ระหว่างจุดยึดและนิ้วของผู้ใช้ ค่าที่ยอมรับได้
คือ "left"
, "right"
, "top"
และ "bottom"
motion:dragDirection
- ทิศทางการปัดของผู้ใช้ หากมีการตั้งค่าแอตทริบิวต์นี้ ระบบจะแปลง
<OnSwipe>
จะมีผลกับการเลื่อนในทิศทางที่ระบุเท่านั้น ค่าที่ยอมรับได้
คือ "dragLeft"
, "dragRight"
, "dragUp"
และ "dragDown"
motion:dragScale
ควบคุมระยะห่างที่มุมมองจะย้ายซึ่งสัมพันธ์กับความยาวของการปัด
ค่าเริ่มต้นคือ 1 ซึ่งหมายความว่ามุมมองจะเลื่อนไปไกลเท่ากับการปัด
หาก dragScale
น้อยกว่า 1 มุมมองจะเคลื่อนไหวน้อยกว่าระยะการปัด
ตัวอย่างเช่น dragScale
เท่ากับ 0.5 หมายความว่าหากการปัดเลื่อนไป 4 ซม. ค่า
มุมมองเป้าหมายเลื่อน 2 ซม.
หาก dragScale
มากกว่า 1 มุมมองจะเลื่อนไปไกลกว่าการปัด
ระยะทาง ตัวอย่างเช่น dragScale
ของ 1.5 หมายความว่าหากการปัดเลื่อนเป็น 4
ซม. มุมมองเป้าหมายขยับ 6 ซม.
motion:maxVelocity
ความเร็วสูงสุดของมุมมองเป้าหมาย
motion:maxAcceleration
ความเร่งสูงสุดของมุมมองเป้าหมาย
มีใน
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา 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,["# <OnSwipe>\n\nSpecifies the action to perform when the user swipes on the layout. The speed of\nthe motion sequence and the motion of the targeted view are affected by the\nspeed and direction of the swipe, subject to the limits you set with optional\nparameters.\n\nThere can be multiple `\u003cOnSwipe\u003e` nodes for a single `\u003cTransition\u003e`, with each\n`\u003cOnSwipe\u003e` specifying a different swipe direction and a different action to\nperform when the user performs that swipe.\n\nSyntax\n------\n\n```xml\n\u003cOnSwipe\n motion:touchAnchorId=\"@id/target_view\"\n motion:touchAnchorSide=\"side\"\n[ motion:dragDirection=\"direction\" ]\n[ motion:dragScale=\"scale\" ]\n[ motion:maxVelocity=\"maxVelocity\" ]\n[ motion:maxAcceleration=\"maxAcceleration\" ]\n /\u003e\n```\n\nAttributes\n----------\n\n`motion:touchAnchorId`\n: View that is being moved by the swipe.\n\n`motion:touchAnchorSide`\n: Side of the target view that the swipe is anchored to. `MotionLayout` keeps a\n constant distance between the anchor and the user's finger. Acceptable values\n are `\"left\"`, `\"right\"`, `\"top\"`, and `\"bottom\"`.\n\n`motion:dragDirection`\n: Direction of the user's swipe motion. If this attribute is set, this\n `\u003cOnSwipe\u003e` only applies to swipes in the specified direction. Acceptable values\n are `\"dragLeft\"`, `\"dragRight\"`, `\"dragUp\"`, and `\"dragDown\"`.\n\n`motion:dragScale`\n\n: Controls the distance the view moves relative to the length of the swipe. The\n default value is 1, indicating that the view moves as far as the swipe does.\n If `dragScale` is less than 1, the view moves less than the swipe distance.\n For example, a `dragScale` of 0.5 means that if the swipe moves 4 cm, the\n target view moves 2 cm.\n\n If `dragScale` is greater than 1, the view moves farther than the swipe\n distance. For example, a `dragScale` of 1.5 means that if the swipe moves 4\n cm, the target view moves 6 cm.\n\n`motion:maxVelocity`\n\n: Maximum velocity of the target view.\n\n`motion:maxAcceleration`\n\n: Maximum acceleration of the target view.\n\nContained in\n------------\n\n- [`\u003cTransition\u003e`](/training/constraint-layout/motionlayout/ref/transition)"]]