Search code examples
androidandroid-animationrotateanimation

How to remove lag when Rotate Animation repeats on Android?


I have built a RotateAnimation in an XML, load it with AnimationUtils and set it to an ImageView. The problem I face is that, when the image is back to its initial position after one round, instead of proceeding straight to the next round, there is a small timeout there, like a lag.

Is there any solution to remove this timeout?

Below you may find the xml of the animation:

<?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="1800"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="infinite"
        android:toDegrees="360"/>
</set>

Thanks in advance!


Solution

  • You need to put the linear_interpolator on the set.

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