如何在Android中检测两个手指点击?
我需要检测我正在使用的如何在Android中检测两个手指点击?,android,multi-touch,gesture,Android,Multi Touch,Gesture,我需要检测我正在使用的Android应用程序中的两个手指点击。我还使用scalegestruedetector和gesturedtector来检测点击、双击、长按和缩放 在我的onTouchEvent方法中,我有: @覆盖 公共布尔onTouchEvent(运动事件){ scalegestruedetector.onTouchEvent(事件); 手势检测器。onTouchEvent(事件); 开关(event.getActionMasked()){ case MotionEvent.ACTIO
Android
应用程序中的两个手指点击。我还使用scalegestruedetector
和gesturedtector
来检测点击、双击、长按和缩放
在我的onTouchEvent
方法中,我有:
@覆盖
公共布尔onTouchEvent(运动事件){
scalegestruedetector.onTouchEvent(事件);
手势检测器。onTouchEvent(事件);
开关(event.getActionMasked()){
case MotionEvent.ACTION\u DOWN:
activePointerId=event.getPointerId(0);
打破
.
.
.
case MotionEvent.ACTION\u指针\u向上:
int pointerId=event.getPointerId(event.getActionIndex());
if(pointerId==activePointerId){
//更改活动指针
}如果(!scaleDetector.isInProgress()&&(event.getPointerCount()==2))为else{
//把手双指轻敲
}
打破
.
.
.
问题是scale也被检测为两个手指点击。有没有解决这个问题的想法?谢谢!我以前也遇到过这样的问题。最后我不得不编写自己的类来扩展GestureDetector。你可以自己实现scale
private int tap_count=0;
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction() & MotionEvent.ACTION_MASK;
switch(action) {
case MotionEvent.ACTION_DOWN : {
++tap_count;
Log.d(LOG_TAG, "MotionEvent.ACTION_DOWN "+tap_count);
break;
}
case MotionEvent.ACTION_MOVE : {
break;
}
case MotionEvent.ACTION_POINTER_DOWN : {
++tap_count;
Log.d(LOG_TAG, "MotionEvent.ACTION_POINTER_DOWN "+tap_count);
break;
}
case MotionEvent.ACTION_POINTER_UP : {
++tap_count;
Log.d(LOG_TAG, "MotionEvent.ACTION_POINTER_UP "+tap_count);
break;
}
case MotionEvent.ACTION_UP : {
--tap_count;
Log.d(LOG_TAG, "MotionEvent.ACTION_UP "+tap_count);
if(tap_count == 2){
tap_count = 0;
Toast.makeText(mContext,"Enableing Accessbility",Toast.LENGTH_SHORT).show();
return true;
}
break;
}
}
return true;
}