逐帧动画ontouch

时间:2012-06-05 08:48:42

标签: android imageview

如何实现触摸图像视图,用于逐帧动画... 我正在使用以下

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

1 个答案:

答案 0 :(得分:0)

设置触摸侦听器,如下所示

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