How to make a smooth image rotation in Android?
You are right about AccelerateInterpolator; you should use LinearInterpolator instead.
You can use the built-in android.R.anim.linear_interpolator
from your animation XML file with android:interpolator="@android:anim/linear_interpolator"
.
Or you can create your own XML interpolation file in your project, e.g. name it res/anim/linear_interpolator.xml
:
<?xml version="1.0" encoding="utf-8"?>
<linearInterpolator xmlns:android="http://schemas.android.com/apk/res/android" />
And add to your animation XML:
android:interpolator="@anim/linear_interpolator"
Special Note: If your rotate animation is inside a set, setting the interpolator does not seem to work. Making the rotate the top element fixes it. (this will save your time.)
Rotate an Imagewith Animation
First of all, what is you minimum SDK requirement? In case it's at least Android 3.0, you can use the newer animation framework, and animate your Image with something like this:
imageView.animate().rotation(180).start();
About the flicker: I wouldn't reset the source image of the ImageView after the rotation, I'd just leave in the original and make sure that the rotation animation fills after the animation, leaving the image rotated. The flicker is most likely caused by the View's relayout/redraw upon changing the source image.
Further visual artifacts (flicker?) may be caused because the original-rotated image and the rotated static image might differ in a few pixels.
android how to rotate an image twice using RotateAnimation
Oh,I just clear the Rotation Animation that was already applied before applying the new rotation animation.
view.clearAnimation();
Progress bar custom image rotate animation
Try this
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="@drawable/dishu"
android:duration="50" />
<item
android:drawable="@drawable/dishu"
android:duration="50" />
<item
android:drawable="@drawable/dishu"
android:duration="50" />
<item android:duration="50">
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_fav"
android:fromDegrees="330"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="1"
android:toDegrees="360" />
</item>
</animation-list>
Android: ImageView Rotate Animation working only once
I am pretty sure that the rotation is kept at the end of the animation. So the second time you try to animate the image it doesn't move because it already is rotated to 1800.
So either reset your image to 0 or rotate it to currentRotation + 1800f
.
Animate rotation of an image in Android
In your onCreate() do
Matrix matrix = new Matrix();
And in onDraw
float angle = (float) (System.currentTimeMillis() % ROTATE_TIME_MILLIS)
/ ROTATE_TIME_MILLIS * 360;
matrix.reset();
matrix.postTranslate(-source.getWidth() / 2, -source.getHeight() / 2);
matrix.postRotate(angle);
matrix.postTranslate(centerX, centerY)
canvas.drawBitmap(source, matrix, null);
invalidate(); // Cause a re-draw
ROTATE_TIME_MILLIS is the full circle time, e.g. 2000 is 2 seconds.
Related Topics
Change Background of Edittext's Error Message
How to Remove White Underline in a Searchview Widget in Toolbar Android
How Disable/Remove Android Activity Label and Label Bar
Gradle Sync Failed: Failed to Find Build Tools Revision 24.0.0 Rc1
How to Repeat Notification Daily on Specific Time in Android Through Background Service
No Repository Found Error in Installing Adt in Eclipse Indigo
Android: Wait on User Input from Dialog
Android Gcm Sender_Id, How to Get It
Simulate Killing of Activity in Emulator
Difference Between Motionevent.Getrawx and Motionevent.Getx
Notification Passes Old Intent Extras
Action Bar Back Button Not Working
How to Deal with Deprecated Classes in Android to Keep Compatibility
How to Detect If Changes Were Made in The Preferences
Android Volley Imageloader - Bitmaplrucache Parameter
Session 'App': Error Installing APK