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);
}
}
答案 0 :(得分:0)
使用
.rotationBy(float value)
方法而不是
.rotation(float value)
方法。在您的情况下,它旋转 TO 360f,但是您希望它旋转 BY 。
因此此代码应该有效:
imageViewA.animate().rotationBy(360f).setDuration(2000);