gpt4 book ai didi

Android 图像在第一次使用 ViewPropertyAnimator 运行后不旋转

转载 作者:行者123 更新时间:2023-11-30 05:05:57 29 4
gpt4 key购买 nike

  • 我在我的布局中设置了两个 ImageView(s),一个在另一个之上,比如 A 和 B。
  • 我已将 B 的 alpha 设置为 0,因此它完全褪色,因为我想通过在我的代码中将适当的 alpha 设置为 1 来控制显示哪个图像。
  • 现在,我还想在图像淡出之前以及在单击 ImageView(s) 时新图像出现在屏幕上之前将图像旋转 360 度。
  • 我正在使用 ViewPropertyAnimator 的 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)

方法。在您的情况下,它旋转 TO 360f,但您希望它旋转 BY 360f。

所以这段代码应该可以工作:

imageViewA.animate().rotationBy(360f).setDuration(2000);

关于Android 图像在第一次使用 ViewPropertyAnimator 运行后不旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54602264/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com