指定用户在布局上滑动时要执行的操作。运动序列的速度和目标视图的运动会受到滑动速度和方向的影响,具体取决于您使用可选参数设置的限制。
一个 <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 厘米,目标视图移动 2 厘米。如果
dragScale
大于 1,则视图移动的距离大于滑动距离。例如,dragScale
为 1.5 表示,如果滑动移动 4 厘米,目标视图移动 6 厘米。motion:maxVelocity
目标视图的最大速度。
motion:maxAcceleration
目标视图的最大加速度。