android - 滑动时减慢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"
解决方案
<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。调高速度和加速度,调低持续时间
长答案
一般来说,滑动动画有两个阶段当您的手指触摸“拖动阶段”而不是“滑动阶段”时
- 拖动阶段 动画跟踪您的手指的拖动阶段。如果您没有设置 touchAnchorId,那么在整个屏幕上拖动会带您从头到尾。如果您设置 touchAnchorId,则拖动与您选择的视图的速度相匹配。视图移动距离的拖动将带您从开始到结束。
- 甩动阶段 甩动的开始速度设置为拖动阶段结束时的速度。目标变为在持续时间内到达开始或结束。加速或减速到最大速度。
因此,对于上面的示例,如果您拖动到中间并向上移动鼠标,它将尝试在一秒钟内让您到达终点,首先以 20 (DDp/s2) 加速到 20 (Dp/ds) 的最大 v 滑行直到时间是正确,使其在 20 处减速,最后停止。
将其视为汽车 maxVelocity 是最高速度。maxAcceleration 是 0-60 的时间。持续时间是您到达那里的时间。
dragScale是在拖动阶段计算的拖动到进度的乘数
我正在简化许多其他细节,但这已经变得复杂了。
推荐阅读
- python - 将RGB转换为灰色时如何解决错误?(错误:(-215)scn == 3 || scn == 4 在函数 cv::cvtColor 中)
- delphi - 我希望能够将附件数据保存到我的 mysql 数据库中。我猜这意味着我必须将附件数据保存到 TStream
- tfs - 为什么这是 tfs 中毫无根据的合并?
- python - 为什么 Seaborn 会在我的数据中创建一个额外的类别?
- python - numpy 数组转换(拆分 int 无需转换为字符串)
- java - 如何并行化高斯消除算法?
- java - 如何将现有的 tomcat 应用程序迁移到 AWS?
- python - Pythonic 用变量中可能的 None 对类进行排序的方法
- laravel - Laravel-vue jwt 令牌刷新
- django - 如何正确序列化其模型具有外键且也采用 ImageField 的对象?