比如说一段旋转动画
RotateAnimation animation = new RotateAnimation(0, 360, mMoveCircle.getMeasuredWidth() / 2, mMoveCircle.getMeasuredHeight() / 2); animation.setDuration(1000); animation.setRepeatCount(3);//共转4圈
这样设定好animation对象后就已经可以用了
mView.startAnimation(animation);
但是会发现旋转过程并非完全匀速
如果我们想要让它完全匀速地旋转,或者加速旋转,或者任何我们想要的速度效果
那么这个时候就可以使用插补器了
例如:
匀速:
LinearInterpolator i = new LinearInterpolator();
animation.setInterpolator(i);
加速:
AccelerateInterpolator i = new AccelerateInterpolator(3);
animation.setInterpolator(i);
遇障反弹:
BounceInterpolator i = new BounceInterpolator();
animation.setInterpolator(i);
以及数个系统自带的效果(它们都是Interpolator接口的子类,可参阅SDK)
如果想要更加客制化的效果,可以写自己的插补器
例如,这里是用一个匿名类来实现的幂函数加速规则
Interpolator i = new Interpolator() { @Override public float getInterpolation(float input) { // TODO Auto-generated method stub // return input*3;//总时长没变,转的圈数增加了 return input*input; } };
本文详细介绍了如何在Android中使用RotateAnimation实现旋转动画,并通过不同的插补器如LinearInterpolator、AccelerateInterpolator和BounceInterpolator来调整动画速度,包括自定义插补器的方法。
1万+

被折叠的 条评论
为什么被折叠?



