2012-06-05 93 views
2

如何實現對圖像視圖觸摸這是由幀動畫用於幀...我使用這個 如下ontouch上逐幀動畫

final AnimationDrawable newtonAnimation = (AnimationDrawable) animation.getBackground(); 

      AnimationStart(newtonAnimation); 

      animation.setOnTouchListener(l); 


public void AnimationStart(final AnimationDrawable newanimation){ 
    Thread timer=new Thread(){ 
     @Override 
     public void run(){ 
          try{ 
            sleep(40); 
           }catch(Exception e){} 
           finally{ 
              Newton_LawsActivity.this.runOnUiThread(new Runnable() { 
               public void run(){ 
               newanimation.start(); 
              }}); 
             } 
          } 
         }; 
    timer.start(); 

} 這是我收到在ontouch事件.......

public boolean onTouch(View v, MotionEvent event) { 
     // TODO Auto-generated method stub 
     Log.w("debug","nullis event"+event+"OR"+gestureDetector.onTouchEvent(event)); 

     return gestureDetector.onTouchEvent(event); 
} 
+0

什麼是AnimationStart(牛頓動畫)? –

+0

那是方法.. – Ashishsingh

+0

是這個方法做的動畫功能嗎? –

回答

0

設置ontouch lintener像下面

   animation.setOnTouchListener(new OnTouchListener() 
       { 
        @Override 
        public boolean onTouch(View v, MotionEvent event) 
        { 
         newtonAnimation.stop(); 
         Toast.makeText(FrameAnimationActivity.this, "animation stoped", Toast.LENGTH_LONG).show(); 
         return false; 
        } 
      }); 
+0

你能解釋我Toast.makeText(FrameAnimationActivity.this,「動畫」,Toast.LENGTH_LONG).show(); – Ashishsingh

+0

吐司只是用於測試觸摸事件,你可以把你的代碼,而不是吐司http://developer.android.com/guide/topics/ui/notifiers/toasts.html –

+0

FrameAnimationActivity.this是你的活動的上下文 –