<OnSwipe>
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
عملی را که هنگام کشیدن انگشت کاربر روی طرحبندی انجام میشود، مشخص میکند. سرعت توالی حرکت و حرکت نمای هدف تحت تأثیر سرعت و جهت کشیدن انگشت قرار میگیرد، مشروط به محدودیتهایی که با پارامترهای اختیاری تعیین میکنید.
میتواند چندین گره <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
حداکثر شتاب نمای هدف.
موجود در
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-29 بهوقت ساعت هماهنگ جهانی."],[],[],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)"]]