Android的图片使用ViewPropertyAnimator第一次运行后不旋转

问题描述 投票:1回答:1
  • 我有两个ImageView的(一个或多个)在其他的顶部在我的布局设置一个,说A和B.
  • 我已经B的阿尔法设置为0,所以它完全褪色如我想控制该图像通过在我的代码设置适当的α1显示。
  • 现在,我也想通过360度,他们淡出的新形象接触屏幕前,当我点击ImageView的(一个或多个)之前,旋转图像。
  • 我使用的是ViewPropertyAnimator的rotation()alpha()方法来做到这一点。
  • 这工作没有任何问题,在安装应用程序时,并运行了第1次。
  • 但是,下一次,当我点击图片,仅淡入和淡出的动画工作。
  • 旋转不起作用。
  • 检查此代码: 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); } }
android android-activity android-animation android-imageview
1个回答
0
投票

使用

.rotationBy(float value)

方法,而不是

.rotation(float value)

方法。在你的情况下,它旋转到360°F,但你希望它旋转BY 360F。

所以这个代码应工作:

imageViewA.animate().rotationBy(360f).setDuration(2000);
© www.soinside.com 2019 - 2024. All rights reserved.