首页 > 解决方案 > 动画完成后如何设置图像可见性

问题描述

我正在尝试在动画结束后设置图像可见性,但我遇到了困难。

我创建了一些图像并为每个图像设置了标签。每当用户单击图像时,可见性都会设置为不可见。我还创建了一个动画图像的方法。我想在动画结束时将图像的可见性重置为可见。抱歉,如果这听起来有点不清楚,我不完全确定如何措辞这个问题。任何帮助,将不胜感激。

  public void popBubbles(View view) {


    final String tag = String.valueOf(view.getTag());

    if(tag=="0"){
        bubble.setVisibility(View.INVISIBLE);
    }else if(tag=="1"){
        bubble1.setVisibility(View.INVISIBLE);

    }else if(tag=="2"){
        bubble2.setVisibility(View.INVISIBLE);


    }else if(tag=="3"){
        bubble3.setVisibility(View.INVISIBLE);

    }else if(tag=="4"){
        bubble4.setVisibility(View.INVISIBLE);
    }else if(tag=="5"){
        bubble5.setVisibility(View.INVISIBLE);
    }else if(tag=="6"){
        bubble6.setVisibility(View.INVISIBLE);
    }else if(tag=="7"){
        bubble7.setVisibility(View.INVISIBLE);
    }else  if(tag=="8"){
        bubble8.setVisibility(View.INVISIBLE);
    }
 }

 public void animateBubbles() {

    for (final ImageView img : IMGS) {


        animation = ObjectAnimator.ofFloat(img, "translationY", 0f, -deviceHeight);
        animation.setDuration(4000);
        animation.start();
        animation.setRepeatCount(ValueAnimator.INFINITE);



    }
}

标签: javaandroidandroid-studio

解决方案


此代码在 kotlin 中,但您可以使用 on AnimationEnd() 方法向动画添加侦听器,如下所示。

animation.addListener(object : Animator.AnimatorListener {
        override fun onAnimationEnd(animation: Animator?) {

        }
    })

希望这可以帮助。


推荐阅读