在做动画时候呢希望做一个可以实现暂停旋转的动画效果,示例如下
/**
* 开始动画
* */
public void startAnimation() {
objectAnimator = ObjectAnimator.ofFloat(luyinyuandianiv, "Rotation", currentValue - 360, currentValue);
// 设置持续时间
objectAnimator.setDuration(1000);
// 设置循环播放
objectAnimator.setRepeatCount(ObjectAnimator.INFINITE);
// 设置动画监听
objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
// TODO Auto-generated method stub
// 监听动画执行的位置,以便下次开始时,从当前位置开始
// animation.getAnimatedValue()为flort类型
currentValue = (float) animation.getAnimatedValue(); } }); objectAnimator.start();}/** * 停止动画 * */public void stopAnimation() { objectAnimator.end(); luyinyuandianiv.clearAnimation(); currentValue = 0;// 重置起始位置}/** * 暂停动画 * */@SuppressLint("NewApi")public void pauseAnimation() { objectAnimator.cancel(); luyinyuandianiv.clearAnimation();// 清除此ImageView身上的动画}@Overridepublic void onDetachedFromWindow() { // TODO Auto-generated method stub super.onDetachedFromWindow(); // 控件被移除时,取消动画 objectAnimator.cancel(); luyinyuandianiv.clearAnimation();// 清除此ImageView身上的动画 luyinyuandianiv.clearAnimation();// 清除此ImageView身上的动画}