Android, disable the swiping to interact with SlidingPaneLayout

后端 未结 5 2096
無奈伤痛
無奈伤痛 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-28 19:39

    This one is a bit tricky. If you always return true in onInterceptTouchEvent() it will dispatch event to the hidden content below. I was able to achieve it like this:

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return !slidingEnabled || super.onInterceptTouchEvent(ev);
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (!slidingEnabled) {
            // Careful here, view might be null
            getChildAt(1).dispatchTouchEvent(ev);
            return true;
        }
        return super.onTouchEvent(ev);
    }
    

提交回复
热议问题