a fair player a fair player - 24 days ago 11
Android Question

Android, disable the swiping to interact with SlidingPaneLayout

I need to disable swiping to open/close SlidingPaneLayout because my main view is a map.
I'll open/close it using a button.

Answer

Subclass SlidingPaneLayout, override onInterceptTouchEvent() and make it always return false. This will prevent SlidingPaneLayout from handling touch events.

See http://developer.android.com/training/gestures/viewgroup.html for more information.

Update:
If touch events are not handled by the child view(s), the SlidingPaneLayout's onTouchEvent() method will be called nevertheless. To completely disable handling touch events also override onTouchEvent() and always return false.

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    return false;
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    return false;
}

Note: The downside of this approach is that touch events still get dispatched to the second child view when it's only partly visible. So you might want to check out the other answers.

Comments