我在我的应用程序中实现 AnimationDrawable 时遇到问题。我参考了开发者指南来实现动画。无论出于何种原因,动画播放后,第一帧和最后一帧在屏幕上仍然可见。
我的 xml 文件如下所示:
<animation-list android:id="@+id/selected"
android:oneshot="true" xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bubbles_1hd" android:duration="50" />
<item android:drawable="@drawable/bubbles_2hd" android:duration="50" />
<item android:drawable="@drawable/bubbles_3hd" android:duration="50" />
<item android:drawable="@drawable/bubbles_4hd" android:duration="50" />
<item android:drawable="@drawable/bubbles_5hd" android:duration="50" />
<item android:drawable="@drawable/bubbles_6hd" android:duration="50" />
<item android:drawable="@drawable/bubbles_7hd" android:duration="50" />
<item android:drawable="@drawable/bubbles_8hd" android:duration="50" />
我的代码如下所示:
ImageView img = (ImageView)findViewById(R.id.imageAnimation);
img.setBackgroundResource(R.drawable.bubble_animation);
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
frameAnimation.setOneShot(true);
frameAnimation.start();
我能够弄清楚的唯一解决方案。将实现为隐藏 ImageView 的动画结束设置的延迟计时器。但是,我希望我缺少一个更简单更优雅的解决方案。
谢谢你的帮助