Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, disable the swiping to interact with SlidingPaneLayout

Tags:

android

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

like image 436
a fair player Avatar asked Jun 08 '13 18:06

a fair player


1 Answers

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.

like image 139
cketti Avatar answered Sep 21 '22 20:09

cketti