ViewPager intercepts all x-axis onTouch events. How to disable?

后端 未结 4 2036
自闭症患者
自闭症患者 2020-11-29 04:22

Scope

There is a viewpager of two fragments. One of those fragments has a layout witch listens to onTouch changes at X-axis.

Problem

Layout doesn\'t

4条回答
  •  野性不改
    2020-11-29 04:58

    You are right, I believe every scrolling container intercepts touch events, but you can prevent it. You can put a touch listener on your layout:

    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_MOVE: 
            pager.requestDisallowInterceptTouchEvent(true);
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            pager.requestDisallowInterceptTouchEvent(false);
            break;
        }
    }
    

提交回复
热议问题