Reputation: 43
rotation()
and alpha()
methods to do this. Check this code :
boolean isImage1Showing = true;
//onClick() method for the 2 ImageView(s)
public void fadeAndRotate(View view){
if (isImage1Showing){
//Rotate the resource on 1st ImageView by 360 degrees
imageViewA.animate().rotation(360f).setDuration(2000);
imageViewA.animate().alpha(0).setDuration(2000);
//Displaying the other image on to the screen
imageViewB.animate().alpha(1).setDuration(2000);
isImage1Showing = false;
} else {
isImage1Showing = true;
imageViewB.animate().rotation(360f).setDuration(2000);
//Displaying the previous image
imageViewA.animate().alpha(1).setDuration(2000);
//fading out the currently displayed image
imageViewB.animate().alpha(0).setDuration(2000);
}
}
Upvotes: 2
Views: 236
Reputation: 3493
Use the
.rotationBy(float value)
method instead of the
.rotation(float value)
method. In your case it rotates TO 360f but you want it to rotate BY 360f.
So this code should work :
imageViewA.animate().rotationBy(360f).setDuration(2000);
Upvotes: 1