简体   繁体   English

具有给定速度的动画?

[英]Animaiton with given velocity?

I am using a VelocityTracker to find out the velocity of a MotionEvent in the onTouch method. 我使用的是VelocityTracker找出一个的速度MotionEvent在onTouch方法。 After the MotionEvent is finished, I want to start an animation (translate a view) with the velocity detected prior and then accelerate/deaccelerate. 在MotionEvent完成之后,我想以事先检测到的速度开始动画(平移视图),然后加速/减速。

To make clear: I'm not asking about duration , i want an animation that starts with a given velocity . 明确地说:我不是在问持续时间 ,我想要一个以给定速度开始的动画。

You will need to implement your own Interpolator that takes a start velocity and interpolates values from there. 您将需要实现自己的Interpolator ,该Interpolator需要一个初始速度并从那里插值。 getInterpolation() is the method you want to override to provide your own interpolation, and the documentation there describes what different return values mean. getInterpolation()是要覆盖以提供自己的插值的方法,该文档中描述了不同的返回值的含义。

In a nutshell, the input is how far along (from 0f to 1f) you are in time, and the output is how far along you want your View to be in its animation. 简而言之, input是您在时间上(从0f到1f)的距离,而输出是您希望View在其动画中的距离。

You will have to do a bit of calculation when creating your interpolator to determine the appropriate return values to respect the initial velocity. 创建内插器时,您需要做一些计算,以确定适合初始速度的适当返回值。

For reference, I would start by looking at the source for the stock AccelerateInterpolator 作为参考,我将从查看股票AccelerateInterpolator的来源开始

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM