动态壁纸onTouchEvent

时间:2011-03-30 09:21:20

标签: android wallpaper

:) 我试图将触摸与幻灯片分开,但我无法做到正确: - 当用户滑动屏幕时,我想只获得幻灯片

                public void onTouchEvent(MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_MOVE ) {                        
                        Log.e(Logcat, "1 slide");              
                    }
                    else
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {                         
                        Log.e(Logcat, "1 touch");              
                    }           

                    super.onTouchEvent(event);                      
            }   

谢谢!


修改

                public void onTouchEvent(MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_MOVE ) {
                        slide = true;
                        Log.e(Logcat, "1 slide");              
                    }
                    else
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        slide = false;             
                    }           
                    else if (event.getAction() == MotionEvent.ACTION_UP)
                    {
                        if(!slide)
                        {
                        touch =1;
                        Log.e(Logcat, "1 touch");
                        }
                    }

                    super.onTouchEvent(event);                      
            }

这不起作用,我得到的是一些幻灯片(即使在触摸时)

1 个答案:

答案 0 :(得分:1)

一些伪代码:

boolean sliding = false;

ontouch() {

  if(move){
     //might do some time/distance checks for these to run
     sliding = true;
     doSlideActions();
  }else if(down){
     sliding = false;
  }else if(up){
     if(!sliding) doDownAction();
  }
}