Parama Sudha Parama Sudha - 2 months ago 6
Android Question

Animation in ImageView is not rotate smoothy

I need to make an ImageView to be rotated. For this I used the following code.

res/anim/rotator.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<rotate
android:duration="6000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="1"
android:toDegrees="359"></rotate>
</set>


Activity.class

final Animation myRotation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotator);
imgSplashLogo.startAnimation(myRotation);


The image is rotated in mycase.
But getting stuck while rotating & not by smooth.
Where may be the mistake in my code.


Please check it.Thanks in advance...

Answer

An interpolator defines the rate of change of an animation. This allows the basic animation effects (alpha, scale, translate, rotate) to be accelerated, decelerated, repeated ;

You need to add android:interpolator="@android:anim/linear_interpolator" in rotate section .

Finally

<set xmlns:android="http://schemas.android.com/apk/res/android"
   >
        <rotate
        android:duration="6000"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="1"
        android:toDegrees="359"
        android:interpolator="@android:anim/linear_interpolator"></rotate>
</set>

You can use setDrawingCacheEnabled(true);

Enabling the drawing cache is similar to setting a layer when hardware acceleration is turned off.