屠龙石头 2013-01-24
对于Android设备来说最主要的操作方式为触控,作为一个Android开发者来说深入了解 GestureDetector 手势识别是很有必要的,Android123今天主要介绍下该类相关的方法,以及简单的手势识别。
通常我们构造GestureDetector类时设置一个GestureDetector.OnGestureListener对象来实时监控用户的操作,OnGestureListener对象提供一些常见手势的重写方法。
@Override
public boolean onDown(MotionEvent e) {
//按下事件
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
//快速滚动
return true;
}
@Override
public void onLongPress(MotionEvent e) {
//长按
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
//常规滚动
return true;
}
@Override
public void onShowPress(MotionEvent e) {
//Android开发网提示为了产生理解异议,SDK原文为 The user has performed a down MotionEvent and not performed a move or up yet. This event is commonly used to provide visual feedback to the user to let them know that their action has been recognized i.e. highlight an element
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
//一次按下弹起
return true;
}
http://www.android123.com.cn/androidkaifa/447.html