Search code examples
androidandroid-studioanimationrotationinfinite

Android animation rotate infinite, without pausing


I can rotate my image infinitely. But my problem is that the image pauses shortly when it reaches 360º and then starts rotating again. It happens the same even when I applied "linear_interpolator". What I want to do is that the image does not pause at all when it starts the next round. So it has to rotate infinitely with same speed at any degree.

Here is my - code. Thanks

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
    android:interpolator="@android:anim/linear_interpolator"
    android:duration="1400"
    android:pivotX="50%"
    android:pivotY="50%"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:repeatMode="restart"
    android:repeatCount="infinite" />
</set>

How I call it on my code

    rotate= AnimationUtils.loadAnimation(context, R.anim.loop_rotate)
    binding.imgSecondLayout.startAnimation(rotate)

Thanks for help! :)


Solution

  • Add animation.setRepeatCount(Animation.INFINITE) to your java class where animation is called.

    My final code is given here:

    Animation animation = AnimationUtils.loadAnimation(getBaseContext(), R.anim.loop_rotate);
    animation.setInterpolator(new LinearInterpolator());
    animation.setRepeatCount(Animation.INFINITE);
    animation.setDuration(1400);
    youractivity.startAnimation(animation);