編輯:關於Android編程
在Android游戲開發中,我們可能經常要像PC操作一樣在屏幕上雙擊。對於屏幕雙擊操作,Android 1.6版本以前並沒有提供完善的手勢識別類,Android 1.5的SDK中提供了android.view.GestureDetector.OnDoubleTapListener,但經測試無法正常工作,不知是何原因。最終我們的解決方案如下面的代碼:
Java代碼
public class TouchLayout extends RelativeLayout {
public Handler doubleTapHandler = null;
protected long lastDown = -1;
public final static long DOUBLE_TIME = 500;
public TouchLayout(Context context) {
super(context);
}
public TouchLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TouchLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public boolean onTouchEvent(MotionEvent event) {
this.handleEvent(event);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
long nowDown = System.currentTimeMillis();
if (nowDown - lastDown < DOUBLE_TIME)
{
if (doubleTapHandler != null)
doubleTapHandler.sendEmptyMessage(-1);
} else {
lastDown = nowDown;
}
}
return true;
}
protected void handleEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
//Do sth 這裡處理即可
break;
case MotionEvent.ACTION_UP:
//Do sth
break;
}
}
}
以上就是對Android 屏幕雙擊的事件捕獲的示例代碼,後續繼續補充相關資料,希望能幫助開發Android應用的朋友。
Android 圖片選擇器
GalleryPick 是 Android 自定義相冊,實現了拍照、圖片選擇(單選/多選)、裁剪、ImageLoader無綁定 任由開發者選擇圖片展示 Gif展示 Ga
android 圖片水平重復平鋪(repeat x)
從零開始學android(chronometer計時器組件.三十二.)
計時器來計算每個運動員所消耗的時間等,而在Android系統之中,這種計時的功能就可以使用Chronometer組件,此類的繼承結構如下所示: 2java.lang.Ob
微信怎麼投訴微商賣家 微信怎麼投訴好友
有時候,我們的微信會收到一些不認識的人發的廣告,甚至是一些微商的詐騙信息,特別一些微信群上,時不時就會遇到一些做垃圾廣告或者不法分子詐騙的,或者不小心就被加