rotation()
和alpha()
方法来做到这一点。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);
}
}使用
.rotationBy(float value)
方法,而不是
.rotation(float value)
方法。在你的情况下,它旋转到360°F,但你希望它旋转BY 360F。
所以这个代码应工作:
imageViewA.animate().rotationBy(360f).setDuration(2000);