2

I have a semi circle that I rotate 180 degrees. If the user presses reset during the RotateAnimation, I want to have a reset animation that goes from currentDegree back to 0. Currently the reset animation goes from 180 to 0, but this looks strange if the animation hasn't finished yet.

I have:

final RotateAnimation resetAnim = 
  new RotateAnimation(-180f, 0f, width, height/2);

I want something like:

final RotateAnimation resetAnim = 
  new RotateAnimation(currentDegreeOfAnimation, 0f, width, height/2);
Rubens Mariuzzo
  • 28,358
  • 27
  • 121
  • 148
Adam Johns
  • 35,397
  • 25
  • 123
  • 176
  • What about calculating it from the animation duration and the difference between start time of animation and time of reset being pressed? A bit of a hack and possibly not very accurate but I don't see anything in the `RotateAnimation` or `Animation` classes which would do what you want directly. – Squonk Jul 15 '13 at 21:01

1 Answers1

1

The speed of the rotation is:

(EndDegree - StartDegree)/Duration

The total time it has been rotating is:

currentTime - startTime

And the current degree is:

speed*time

I believe you have access to all of these variables through getters, except for current time which is just System.currentTimeMillis(), don't forget to keep your units straight.

user2483079
  • 533
  • 2
  • 10
  • if the i pause the rotate animation this will no longer work will it? starttime will be distorted. – Adam Johns Jul 16 '13 at 14:25
  • 1
    It wouldn't be quite so simple, no. If pausing is a factor then you will need to account for downtime as well and subtract it from the total time. – user2483079 Jul 16 '13 at 14:27