日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Android游戲開發(fā)之十九:屏幕雙擊事件的捕獲

在Android游戲開發(fā)中,我們可能經(jīng)常要像PC操作一樣在屏幕上雙擊。對于屏幕雙擊操作,Android 1.6版本以前并沒有提供完善的手勢識別類,Android 1.5的SDK中提供了android.view.GestureDetector.OnDoubleTapListener,但經(jīng)測試無法正常工作,不知是何原因。最終我們的解決方案如下面的代碼:

 
 
  1. public class TouchLayout extends RelativeLayout {   
  2.     public Handler doubleTapHandler = null;   
  3.     protected long lastDown = -1;   
  4.     public final static long DOUBLE_TIME = 500;   
  5.  public TouchLayout(Context context) {   
  6.        super(context);   
  7.     }   
  8.     public TouchLayout(Context context, AttributeSet attrs) {   
  9.        super(context, attrs);   
  10.     }   
  11.     public TouchLayout(Context context, AttributeSet attrs, int defStyle) {   
  12.        super(context, attrs, defStyle);   
  13.     }   
  14.     public boolean onTouchEvent(MotionEvent event) {   
  15.          this.handleEvent(event);   
  16.          if (event.getAction() == MotionEvent.ACTION_DOWN) {   
  17.             long nowDown = System.currentTimeMillis();   
  18.             if (nowDown - lastDown < DOUBLE_TIME)   
  19.             {   
  20.                   if (doubleTapHandler != null)   
  21.                      doubleTapHandler.sendEmptyMessage(-1);   
  22.             } else {   
  23.                lastDown = nowDown;   
  24.             }   
  25.          }   
  26.          return true;   
  27.       }   
  28.     protected void handleEvent(MotionEvent event) {   
  29.         switch (event.getAction()) {   
  30.         case MotionEvent.ACTION_DOWN:   
  31.          //Do sth 這里處理即可   
  32.            break;   
  33.         case MotionEvent.ACTION_UP:   
  34.            //Do sth   
  35.            break;   
  36.         }   
  37.      }   
  38. }  

當(dāng)前標(biāo)題:Android游戲開發(fā)之十九:屏幕雙擊事件的捕獲
本文路徑:http://m.5511xx.com/article/cdpgohp.html