2013-02-26 91 views
0

当我触摸屏幕并移动手指时,我会做一些事情(pullanimation1和2),当我释放屏幕时,我会做其他事情(fireanimation1和2)。有时候,当pullAnimation或fireAnimation正在运行时,用户可能会触摸屏幕,当动画运行几次时,我会收到错误。我想确保当用户再次触摸屏幕时动画不会再运行一次。 注:pullAnimation1和2,fireAnimation 1和2是AnimationDrawable 这里是我做了什么:当onTouch()已经被调用时触摸屏幕

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; 
     } 
    }); 

回答

1

我想你应该能够使用hasStarted()和hasEnded()方法来确定,如果你的动画目前正在进行。 See the docs for more

一些,如果这样的说法可能工作:

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

我想你也可能需要使用reset()它做是为了或方法,以返回正确的价值观下一次发生触摸播放后。

编辑: AnimationDrawableisRunning()方法,这使得它甚至比查看动画更加容易。

if(fireAnimation1.isRunning() == false){ 
    startAnimation(fireAnimation1, fireAnimation2); 
} 
+0

谢谢,但pullAnimation1和2,fireAnimation1和2是AnimationDrawable,所以我不能使用hasStarted,hasEnded,编辑:我试着跑! – morg 2013-02-26 15:08:05

+0

这就是你应该在你的问题中加入的那种东西=)。看我的编辑。 – FoamyGuy 2013-02-26 15:12:15

+0

是的,我编辑后,谢谢 – morg 2013-02-26 15:19:36