0

我在我的应用程序中实现 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 的动画结束设置的延迟计时器。但是,我希望我缺少一个更简单更优雅的解决方案。

谢谢你的帮助

4

1 回答 1

0

我为此找到的解决方案是为可绘制对象的第一张和最后一张幻灯片插入透明图像。不确定这是否是最好的方法,但它有效。

于 2013-02-03T06:34:48.193 回答