Android 停止动画,直到显示特定的可绘制图形
我有一个AnimationDrawable,显示数字0-9 活动启动时,动画也会启动 它从0开始,然后是1,2,3。。。。。。。停在图片“9”处 当显示f.e.“5”时,我如何停止这个小动画 有没有带while循环的解决方案Android 停止动画,直到显示特定的可绘制图形,android,animation,Android,Animation,我有一个AnimationDrawable,显示数字0-9 活动启动时,动画也会启动 它从0开始,然后是1,2,3。。。。。。。停在图片“9”处 当显示f.e.“5”时,我如何停止这个小动画 有没有带while循环的解决方案 ImageView view = (ImageView)findViewById(R.id.iv); AnimationDrawable animation = (AnimationDrawable)iv.getBackground(); animation.start()
ImageView view = (ImageView)findViewById(R.id.iv);
AnimationDrawable animation = (AnimationDrawable)iv.getBackground();
animation.start();
您可以尝试以下方法进行操作:
final ImageView imageView = (ImageView)findViewById(R.id.image);
if (null != imageView) {
final AnimationDrawable bgAnimation = (AnimationDrawable) imageView.getBackground();
bgAnimation.start();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
bgAnimation.stop();
}
}, 5500);
}
假设您有动画xml,如下所示:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="@drawable/choose12"
android:duration="1000"/>
<item
android:drawable="@drawable/choose12_1"
android:duration="1000"/>
<item
android:drawable="@drawable/choose12_2"
android:duration="1000"/>
<item
android:drawable="@drawable/choose12_3"
android:duration="1000"/>
<item
android:drawable="@drawable/choose12_4"
android:duration="1000"/>
<item
android:drawable="@drawable/choose12_5"
android:duration="1000"/>
<item
android:drawable="@drawable/choose12_6"
android:duration="1000"/>
<item
android:drawable="@drawable/choose12_7"
android:duration="1000"/>
<item
android:drawable="@drawable/choose12_8"
android:duration="1000"/>
<item
android:drawable="@drawable/choose12_9"
android:duration="1000"/>
</animation-list>
如果您需要更好地控制动画过程。一些可能会很有用。您正在播放哪个动画以及如何播放?您是否尝试过发布(使用新的处理程序().postdayed())第5帧的确切时间并调用stop()?不,我没有尝试。我不知道该怎么回答我的问题如果你知道调用start()
的时间,每个帧到目标帧的时间(使用getDuration(I)
),那么你可以近似地计算何时调用stop()
(使用Runnable
)。