I need to disable swiping to open/close SlidingPaneLayout because my main view is a map. I\'ll open/close it using a button.
Building on Roman Zhilichs answer with two improvements.
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return !swipeEnabled || super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (!swipeEnabled) {
if (!getChildAt(0).dispatchTouchEvent(ev)) {
ev.offsetLocation(-getChildAt(0).getWidth(),0);
getChildAt(1).dispatchTouchEvent(ev);
}
return true;
}
return super.onTouchEvent(ev);
}
First, this tries to dispatch the MotionEvent to the first child before dispatching it to the second. This way, both child views stay interactive. Second, MotionsEvents dispatched to the second child view must be offset by the width of the first view. This assumes that the sliding pane slides in from the left, as is usual with SlidingPaneLayout.