Search code examples
androidandroid-animationrotateanimation

Android animation to rotate a image around its centre point


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 .


Solution

  • Answering on behalf of @Mahfa

    You have to set pivotX and pivotY to "50%"

    The important part is the percentage.