首页 > 解决方案 > 滑动时减慢motionLayout动画

问题描述

我有motionLayout动画transition

<Transition
        app:constraintSetEnd="@+id/end"
        app:constraintSetStart="@+id/start">
        <OnSwipe
            app:dragDirection="dragUp"
            app:dragScale="0.1"
            app:touchAnchorId="@id/my_scrollview" />
</Transition>

但动画对我来说太快了。我想让它慢下来。我尝试设置dragScale=0.1, maxAcceleration=1, maxVelocity=1,但它不会影响动画速度。我怎样才能让它慢下来?

更新:问题已在较新版本中得到修复,constraintlayout并且似乎正在处理"2.0.4"

标签: androidandroid-motionlayout

解决方案


 <Transition
    motion:constraintSetEnd="@+id/end"
    motion:constraintSetStart="@id/start"
    motion:staggered="0.1"
    motion:duration="1000">

    <OnSwipe 
        motion:touchAnchorId="@id/view"
        motion:dragDirection="dragDown"
        motion:maxVelocity="20"
        motion:maxAcceleration="20"/>
 </Transition>

简短回答:修改持续时间、touchAnchorId、maxVelocity、maxAcceleration。调高速度和加速度,调低持续时间

长答案

一般来说,滑动动画有两个阶段当您的手指触摸“拖动阶段”而不是“滑动阶段”时

  1. 拖动阶段 动画跟踪您的手指的拖动阶段。如果您没有设置 touchAnchorId,那么在整个屏幕上拖动会带您从头到尾。如果您设置 touchAnchorId,则拖动与您选择的视图的速度相匹配。视图移动距离的拖动将带您从开始到结束。
  2. 甩动阶段 甩动的开始速度设置为拖动阶段结束时的速度。目标变为在持续时间内到达开始或结束。加速或减速到最大速度。

因此,对于上面的示例,如果您拖动到中间并向上移动鼠标,它将尝试在一秒钟内让您到达终点,首先以 20 (DDp/s2) 加速到 20 (Dp/ds) 的最大 v 滑行直到时间是正确,使其在 20 处减速,最后停止。

将其视为汽车 maxVelocity 是最高速度。maxAcceleration 是 0-60 的时间。持续时间是您到达那里的时间。

dragScale是在拖动阶段计算的拖动到进度的乘数

我正在简化许多其他细节,但这已经变得复杂了。


推荐阅读