Android, disable the swiping to interact with SlidingPaneLayout

后端 未结 5 2097
無奈伤痛
無奈伤痛 2020-12-28 18:57

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

5条回答
  •  春和景丽
    2020-12-28 19:42

    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.

提交回复
热议问题