歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

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

更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11

Copyright © Linux教程網 All Rights Reserved