Adam Johns
Adam Johns

Reputation: 36343

How to get the current degree of RotateAnimation in Android?

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);

Upvotes: 2

Views: 1155

Answers (1)

user2483079
user2483079

Reputation: 533

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.

Upvotes: 1

Related Questions