使用matrix.postRotate旋转图像时旋转速度有多慢?

时间:2018-03-17 19:14:01

标签: android animation matrix imageview

我希望减慢动画速度,因为我使用下面的代码来旋转ImageView

matrix.postRotate(degrees);

1 个答案:

答案 0 :(得分:0)

我是在某一时刻做到这一点,从我记得我最终使用的是ValueAnimator。它是这样的:

ValueAnimator animation = ValueAnimator.ofFloat(0f, 90f);
animation.setDuration(1000);
animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator updatedAnimation) {
        float animatedValue = (float)updatedAnimation.getAnimatedValue();
        matrix.postRotate(animatedVlaue);
    }
});
animation.start();

声明: 上面的数学是def off,你不能只是postRotate完整的动画值,你将最终过度旋转(如果动画值是1,2,4,9等,那么你将最终旋转1,3,7, 16等)。我无法找到相关的代码,但我通过跟踪先前的动画值然后在它与当前动画值之间的增量上执行postRotate来解决它。

希望有道理!如果没有,请随意发表评论。