2

如何在用于逐帧动画的图像视图上实现触摸......我使用它如下

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

1 回答 1

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;
                    }
            });
于 2012-06-05T09:30:29.050 回答