a fair player a fair player - 1 year ago 103
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 Source

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.

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.

public boolean onInterceptTouchEvent(MotionEvent ev) {
    return false;

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download