0

当我触摸屏幕并移动手指时,我会做一些事情(pullanimation1 和 2),而当我释放屏幕时,我会做其他事情(fireanimation1 和 2)。有时,用户可能会在 pullAnimation 或 fireAnimation 运行时触摸屏幕,然后在动画运行多次时出现错误。我想确保当用户再次触摸屏幕时动画不会运行超过一次。注意:pullAnimation1 和 2,fireAnimation 1 和 2 是 AnimationDrawable 这是我所做的:

    image2.setOnTouchListener(new OnTouchListener(){

        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            boolean bool=false;
            boolean bool2=true;
            int action = arg1.getAction() & MotionEvent.ACTION_MASK;

            switch (action) {
            case MotionEvent.ACTION_DOWN:
            if (bool2) {
            startAnimation(pullAnimation1,pullAnimation2);
            bool=true;
            }
            break;
            case MotionEvent.ACTION_MOVE:
                if (bool2==true){
                Log.w("GAMEACTIVITY","move");
                bool=true;
                bool2=false;
                }
                break;
            case MotionEvent.ACTION_UP:
                startAnimation(fireAnimation1,fireAnimation2);
                bool=false;
                doPhotoTask();
                bool2=false;
                break;
            }
            return bool;
        }
    });
4

1 回答 1

1

我认为您应该能够使用 hasStarted() 和 hasEnded() 方法来确定您的动画当前是否正在播放。有关更多信息,请参阅文档

像这样的一些 if 语句可能会起作用:

if((fireAnimation1.hasStarted() == false) || (fireAnimation1.hasEnded == true()){
  startAnimation(fireAnimation1, fireAnimation2);
}

我想您可能还需要reset()在完成播放后使用,或者在下次触摸发生时返回正确值的方法。

编辑: AnimationDrawable有一个isRunning()方法,它比查看动画更容易。

if(fireAnimation1.isRunning() == false){
  startAnimation(fireAnimation1, fireAnimation2);
}
于 2013-02-26T15:02:01.970 回答