
定义你的插值器
INTERPOLATOR = new AccelerateInterpolator();
在计算 scaleVelocity 时,获取当前插值
float interpolatedValue = INTERPOLATOR.getInterpolation(frameCount / numberOfFrames);
getInterpolation() 返回一个介于 0(动画开始)和 1(动画结束)之间的值
scaleVelocity = (MAX_SCALE-MIN_SCALE)/numberOfFrames * interpolatedValue; // use min,max func if needed.
加速插值器的数学方程是 f(x) = x²,如果你想要更大的变化,那么创建你的自定义插值器。
动画的工作测试方法。
private void testAnim() {
int numberOfFrames = 100;//Math.round((float)ANIMATION_TIME/GameLoopThread.FRAME_PERIOD);
float frameCount = 0;
float MAX_SCALE = 4;
float MIN_SCALE = 0.1f;
float scaleVelocity;
float currentScale ;
Interpolator INTERPOLATOR = new AccelerateInterpolator();
do {
float interpolatedValue = INTERPOLATOR.getInterpolation(frameCount / numberOfFrames);
scaleVelocity = (MAX_SCALE - MIN_SCALE) * interpolatedValue;
currentScale = Math.max(MIN_SCALE, scaleVelocity);
++frameCount;
Log.d("STACK", "testAnim: currentScale = " + currentScale);
// apply scale to view.
} while (frameCount < numberOfFrames);
// finally set final value of animation.
currentScale = MAX_SCALE;
// apply scale to view.
}