java - 动画完成后如何设置图像可见性
问题描述
我正在尝试在动画结束后设置图像可见性,但我遇到了困难。
我创建了一些图像并为每个图像设置了标签。每当用户单击图像时,可见性都会设置为不可见。我还创建了一个动画图像的方法。我想在动画结束时将图像的可见性重置为可见。抱歉,如果这听起来有点不清楚,我不完全确定如何措辞这个问题。任何帮助,将不胜感激。
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);
}
}
解决方案
此代码在 kotlin 中,但您可以使用 on AnimationEnd() 方法向动画添加侦听器,如下所示。
animation.addListener(object : Animator.AnimatorListener {
override fun onAnimationEnd(animation: Animator?) {
}
})
希望这可以帮助。
推荐阅读
- ruby - Ruby 有“等于或”运算符吗?
- sql - Oracle SQL 数据修改
- python - 如果字典列表具有相同的特定值,则用另一字典列表的值更新一个字典列表
- c# - 使用复合设计模式时的 Unity-NullReferenceException
- user-interface - 使用 nuklar 包创建带有按钮的 GUI 的最少代码
- python - 来自vim for python的合成器的令人讨厌的窗口
- html - 背景图像不显示图像 - 但
我正在使用 background-image:url('image') 在我的 HTML 页面中包含一些图标。但是,会显示一个空白区域并且图像不存在。我正在使用一个空标签。当我使用标签时,图像显示成功。你能告诉我我做错了什么吗?这是我的代码: