1

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...

Sreehari
  • 5,621
  • 2
  • 25
  • 59
Parama Sudha
  • 2,583
  • 3
  • 29
  • 48

2 Answers2

2

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.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

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

Finally

<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>