由于在onTouchEvent中判断用户手势的真实想法很不容易,因此Android提供了GestureDetector检测器来帮助我们识别手势。借助于GestureDetector,可以在大多数场合下辨别出常用的几个手势事件,如点击、长按、翻页等等。下面是GestureDetector的相关方法:
 构造函数 : GestureDetector(Context context, OnGestureListener listener)
 监听器类名 : OnGestureListener
 设置监听器的方法,先给指定控件注册触摸监听器,然后在触摸方法onTouch中由GestureDetector接管触摸事件 : 
class="brush:csharp;gutter:true;">private ScrollTextView tv_rough;  
private GestureDetector mGesture;  
  
    tv_rough = (ScrollTextView) findViewById(R.id.tv_rough);  
    tv_rough.setOnTouchListener(this);  
    mGesture = new GestureDetector(this, this);  
      
@Override  
public boolean onTouch(View v, MotionEvent event) {  
    return mGesture.onTouchEvent(event);  
}  
另外,也可在当前视图或当前Activity中重写onTouchEvent方法,在该方法中由GestureDetector接管触摸事件。
 监听器需要重写的方法 : 
 onDown : 在用户按下时调用
 onShowPress : 已按下但还未滑动或松开时调用,通常用于pressed状态时的高亮显示
 onSingleTapUp : 在用户轻点一下再弹起时调用,通常用于点击事件
 onScroll : 在用户滑动过程中调用
 onLongPress : 在用户长按时调用,通常用于长按事件
 onFling : 在用户飞快掠出一段距离时调用,通常用于翻页事件