最近有个需求要做旋转进度条的效果,美术提供了图片,用ImageView使用旋转动画发现有个问题,就是每圈旋转结束后会停顿一下,网上查资料说是因为默认的动画差值器会先加速后减速导致了停顿,使用**LinearInterpolator** 这个差值器就可以做到匀速转动。试了一下确实没有了加速减速的问题了,但每圈结束依然有停顿,确实比之前停顿时间短了不少,但肉眼依然可清楚的看到停顿,这样是不行的。最后找到了解决方案,就是将 **toDegrees** 跟 **duration** 增大一万倍,那么大概转5小时才会停顿一下,相当于把很小的停顿弱化了一万倍,几乎可以忽略不计,很好的解决了这个问题,具体代码如下: ```java RotateAnimation animation; int magnify = 10000; int toDegrees = 360; int duration = 2000; toDegrees *= magnify; duration *= magnify; animation = new RotateAnimation(0,toDegrees, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); animation.setDuration(duration); LinearInterpolator lir = new LinearInterpolator(); animation.setInterpolator(lir); animation.setRepeatCount(Animation.INFINITE); animation.setRepeatMode(Animation.RESTART); mIvBg.startAnimation(animation); ```
Android 旋转动画(RotateAnimation)无限旋转每圈结束停顿问题
最新推荐文章于 2024-04-01 11:27:11 发布