我在下面试过通过放入我的片段布局来禁用两个手指触摸但是没有工作android:splitMotionEvents="false"
我也在下面的清单中尝试过:<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
没有帮助。
如果有人知道怎么请让我知道。感谢
答案 0 :(得分:3)
gestureOverlayView.setOnTouchListener(new View.OnTouchListnener(){
@Override
public boolean onTouch(View v, MotionEvent e){
// True means the event is ignored by the overlayed views
return e.getPointerCount() > 1 ? true : false;
}
}
你可以在整个屏幕上放置一个GestureOverlayView,只允许第一次触摸事件。
答案 1 :(得分:0)
你可以在Stackoverflow上找到这个答案
答案 2 :(得分:0)
使用以下代码检查运行时多点触控并禁用它:
private SparseArray<PointF> mActivePointers= new SparseArray<PointF>();
yourlayoutname.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int pointerIndex = event.getActionIndex();
// get pointer ID
int pointerId = event.getPointerId(pointerIndex);
// get masked (not specific to a pointer) action
int maskedAction = event.getActionMasked();
switch (maskedAction) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN: {
// We have a new pointer. Lets add it to the list of pointers
PointF f = new PointF();
f.x = event.getX(pointerIndex);
f.y = event.getY(pointerIndex);
mActivePointers.put(pointerId, f);
if (mActivePointers.size() >= 2) {
//DO NOTHING
}
break;
}
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_CANCEL: {
mActivePointers.remove(pointerId);
break;
}
}
return true;
}
});