GettingSignals

[Android]ジェスチャー操作を検知するメモ

2011年9月13日
Posted by hina

Androidでジェスチャー操作を検知する方法です。

GestureDetectorを使います。

シングル/ロングタップ、フリック、スクロールなどを検知できる。

onTouchEventを実装していた場合、
GestureDetectorにイベントを渡してあげないと検知できない。
true返却しないと、ジェスチャー検知できない。

  @Override
  public boolean onTouchEvent(MotionEvent event) {
      boolean b = mDetector.onTouchEvent(event);
          return true;
  }

GestureListenerはこんな感じ。
  public class GestureListener extends SimpleOnGestureListener implements OnGestureListener {
  @Override
  public boolean onDoubleTap(MotionEvent e) {
  super.onDoubleTap(e);
  }
 
  @Override
  public void onLongPress(MotionEvent e) {
  super.onLongPress(e);
  }
 
  }
ほかにもonScroll、onFlingとかある。
以上、メモおわり。
Share

Comments are currently closed.

Follow

カレンダー

2024年4月
1234567
891011121314
15161718192021
22232425262728
2930