给一个view添加旋转动画,并且停止后保持旋转角度,恢复后可继续旋转

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mr_jianrong/article/details/80645694

   RotateAnimation这个动画类 animation.setFillAfter(true);方法是在动画自动停止后保持原位,而手动停止调用clearAnimation()后旋转的控件会变成最开始的位置,想到的解决方  法是让动画旋转30度 利用handle不断的发送消息 当点击停止后取消发送消息,不是很好的解决办法。

    经过查找资料发现 ObjectAnimator属性动画

        ObjectAnimator    animator = ObjectAnimator.ofFloat(im_scan, "rotation", 0f, 360.0f);
        animator.setDuration(2000);
        animator.setInterpolator(new LinearInterpolator());//不停顿
        animator.setRepeatCount(-1);//设置动画重复次数
        animator.setRepeatMode(ValueAnimator.RESTART);//动画重复模式

       animator.start();//开始动画

       animator.pause();//暂停动画

       animator.resume();//恢复动画

       这几个方法就能实现效果。

猜你喜欢

转载自blog.csdn.net/mr_jianrong/article/details/80645694