Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何重放单镜头动画_Android_Android Animation - Fatal编程技术网

Android 如何重放单镜头动画

Android 如何重放单镜头动画,android,android-animation,Android,Android Animation,我想制作一个单镜头动画,但能够播放它的次数,因为我想。现在它只是第一次播放 .xml: 只需在aw.start()之前调用aw.stop() frameAnimation.setOneShot(true); 改变 android:oneShot="true" to android:oneShot="false" 如果要在上一个动画完成后重播单镜头动画,可以执行以下操作 final AnimationDrawable animationDrawable = (AnimationDrawable

我想制作一个单镜头动画,但能够播放它的次数,因为我想。现在它只是第一次播放

.xml:

只需在aw.start()之前调用aw.stop()

frameAnimation.setOneShot(true);
改变

android:oneShot="true" to
android:oneShot="false"

如果要在上一个动画完成后重播单镜头动画,可以执行以下操作

final AnimationDrawable animationDrawable = (AnimationDrawable) image.getDrawable();
if (!animationDrawable.isRunning()) {

    int totalFrameDuration = 0;
    for (int i = 0; i < animationDrawable.getNumberOfFrames(); i++) {
        totalFrameDuration += animationDrawable.getDuration(i);
    }

    animationDrawable.start();
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            animationDrawable.stop();
        }
    }, duration);
}
final AnimationDrawable AnimationDrawable=(AnimationDrawable)image.getDrawable();
如果(!animationDrawable.isRunning()){
int totalFrameDuration=0;
对于(int i=0;i
经过几个小时的努力,我在发布问题后找到了正确的答案。最糟糕的是。。。这是第二次发生在我身上。所以现在我不知道是否应该在发布问题之前多多少少等待:/Thank slipbull:)(Y)我尝试了这个解决方案,它对我有效。但我还是不明白为什么它解决了这个问题!!我的意思是,先叫停再叫开始是不合逻辑的@slipbull我需要调用aw.selectDrawable(0)来完全重置AnimationDrawable,否则它将再次运行,就是这样。oneShot:true/false将执行一次或永远循环
android:oneShot="true" to
android:oneShot="false"
final AnimationDrawable animationDrawable = (AnimationDrawable) image.getDrawable();
if (!animationDrawable.isRunning()) {

    int totalFrameDuration = 0;
    for (int i = 0; i < animationDrawable.getNumberOfFrames(); i++) {
        totalFrameDuration += animationDrawable.getDuration(i);
    }

    animationDrawable.start();
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            animationDrawable.stop();
        }
    }, duration);
}