2

I have an image and am simply attempting to spin it (rotate 360) a number of times around its center. However, my attempts just result in the image making a wide circle - I think around the upper left of the containing view.

I found this How to spin an android icon on its center point? which seems very similar, but how to do this in an XML animation definition?

My animation XML:

<rotate
   android:fromDegrees="0"
   android:toDegrees="360"
   android:pivotX="50%"
   android:pivotY="50%"
   android:duration="1600"
   android:repeatCount="infinite"
/>
Community
  • 1
  • 1
drawk
  • 309
  • 4
  • 10

1 Answers1

0

Why don't you use the image as a progressbar. It will rotate it's centre number of times till you dismiss it.

Try this code

 ImageView diskView = (ImageView) findViewById(R.id.imageView3);

    // Create an animation instance
    Animation an = new RotateAnimation(0.0f, 360.0f, pivotX, pivotY);

    // Set the animation's parameters
    an.setDuration(10000);               // duration in ms
    an.setRepeatCount(0);                // -1 = infinite repeated
    an.setRepeatMode(Animation.REVERSE); // reverses each repeat
    an.setFillAfter(true);               // keep rotation after animation

    // Apply animation to image view
    diskView.setAnimation(an);
selva
  • 1,175
  • 1
  • 19
  • 39
Saraschandraa
  • 478
  • 1
  • 10
  • 28
  • Hmm, it may work, but not sure if that is the approach I'm ready to take. The rotating will be part of a larger animation set - this image is a ball and during a kickoff it will be translated and scaled as well as rotated. The image is also used in other ways (not rotating) in different parts of the app. Overall, I'd like to understand why rotate doesn't work as I expected it to, and what I am doing incorrectly. – drawk Mar 13 '14 at 13:02