Reputation: 22566
I am struggling with an android xml animation. I want to rotate an image anti clockwise around its central point.
Here is my xml for the animation:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<rotate
android:duration="1000"
android:repeatCount="infinite"
android:repeatMode="restart"
android:fromDegrees="360"
android:toDegrees="0"
android:pivotX="0.5"
android:pivotY="0.5"
android:interpolator="@android:anim/linear_interpolator"
/>
No this current animation rotates the image around the point x=0 ; y=0 .
Upvotes: 1
Views: 2639
Reputation: 22566
Answering on behalf of @Mahfa
You have to set pivotX and pivotY to "50%"
The important part is the percentage.
Upvotes: 3
Reputation: 1974
I think that you need to use a Matrix object. I did the same some time ago and I remember that I had the same issue than you:
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, config);
Canvas canvas = new Canvas(targetBitmap);
Matrix matrix = new Matrix();
matrix.setRotate(mRotation,source.getWidth()/2,source.getHeight()/2);
canvas.drawBitmap(source, matrix, new Paint());
Edit: use this function with a timer handler
public Bitmap rotateImage(int angle, Bitmap bitmapSrc) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(bitmapSrc, 0, 0,
bitmapSrc.getWidth(), bitmapSrc.getHeight(), matrix, true);
}
Upvotes: 0