Android中实现双击屏幕跳转


Android中实现双击屏幕跳转

2个类

一个是Activity

另一个是OnDoubleClick事件处理类

import android.app.Activity; 2 import android.os.Bundle; 3 import android.view.GestureDetector; 4 import android.view.MotionEvent; 5 import android.view.View.OnTouchListener; 6  7 /** 8  *  9  * <p>class instruction:内部界面 核心Activity</p>10  * create in 2011-12-2 @author Mercury11  */12 public class GameActivity extends  Activity {13    GameActivityHelper helper;14    private GestureDetector gd;15    @Override16    public void onCreate(Bundle savedInstanceState) {17        super.onCreate(savedInstanceState);18        helper=new GameActivityHelper(this);19        helper.init();20        setContentView(helper.getGameView());21        gd=new GestureDetector(this,new OnDoubleClick());22    }23      @Override24    public boolean onTouchEvent(MotionEvent event) {25        return gd.onTouchEvent(event);26    }27 }1 import android.app.Activity;
 import android.os.Bundle;
 import android.view.GestureDetector;
 import android.view.MotionEvent;
 import android.view.View.OnTouchListener;
 
/**
 *
* <p>class instruction:内部界面 核心Activity</p>
 * create in 2011-12-2 @author Mercury
*/
 public class GameActivity extends Activity {
 GameActivityHelper helper;
private GestureDetector gd;
 @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
 helper=new GameActivityHelper(this);
 helper.init();
 setContentView(helper.getGameView());
 gd=new GestureDetector(this,new OnDoubleClick());
 }
 @Override
public boolean onTouchEvent(MotionEvent event) {
return gd.onTouchEvent(event);
 }
 }

--------------------------------------

 import android.view.GestureDetector;
 import android.view.MotionEvent;
 
public class OnDoubleClick extends GestureDetector.SimpleOnGestureListener{
 @Override
public boolean onDoubleTap(MotionEvent e) {
//TODO
return true;
 }
 // @Override
 // public boolean onDoubleTapEvent(MotionEvent e) {
 // return super.onDoubleTapEvent(e);
 // }
 }

相关内容