vivek
vivek

Reputation: 151

How to disable two finger touch on layout in android

I have tried below to disable two finger touch by putting in my fragment layout but did not workandroid:splitMotionEvents="false" Also i tried below in manifest: <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" /> No help.

If anyone knows how to please let me know. Thanks

Upvotes: 0

Views: 3182

Answers (3)

Payal Javiya
Payal Javiya

Reputation: 120

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;
    }
}

You can put a GestureOverlayView the whole screen and only allow the first touch event.

Upvotes: 1

Mahesh Keshvala
Mahesh Keshvala

Reputation: 1355

Use Below code to check run time multitouch and disable it:

    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;
        }
    });

Upvotes: 0

Ashish Kumar Maurya
Ashish Kumar Maurya

Reputation: 174

You can refer to this answer already there on Stackoverflow

Disable multi finger touch in my app

Upvotes: 0

Related Questions