<スワイプオン>
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
レイアウト上でスワイプされたときに実行するアクションを指定します。Google の
ターゲット ビューのモーション シーケンスと
スワイプの速度と方向。オプションの
あります。
1 つの <Transition>
に複数の <OnSwipe>
ノードを配置でき、
<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 cm 移動した場合、
ターゲット ビューが 2 cm 移動します。
dragScale
が 1 より大きい場合、ビューはスワイプよりも遠くに移動します
ありますたとえば、dragScale
が 1.5 の場合、スワイプが 4 移動した場合です。
cm に移動すると、ターゲット ビューが 6 cm 移動します。
motion:maxVelocity
ターゲット ビューの最大速度。
motion:maxAcceleration
ターゲット ビューの最大加速度。
親要素
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[null,null,["最終更新日 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)"]]