当我使用RecyclerView + Viewpager + RecyclerView时,我遇到了问题

时间:2018-09-07 08:56:22

标签: android android-recyclerview android-viewpager

enter image description here

需要解决滑动冲突。

当我的手指向上滑动时,滑动至选项卡吸顶,继续向上滑动,此时,我希望内部RecyclerView处理滑动事件。但是我希望手指再次抬起并滑动,我的代码才能生效。外部RecyclerView是自定义的。

我重写了其onInterceptTouchEvent方法。但是此方法不会实时回调。我试图重写onTouchEvent方法,以告诉它在Tab吸吮顶部时不要拦截滑动事件,该方法仍然无效。在不将滑动事件移至内部RecyclerView处理的情况下,我们应该怎么做才能举起手指? 这个场景有点复杂。如果我没有清楚描述,请直接留言,谢谢!!!

@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
    float x= e.getX();
    float y = e.getY();
    switch (e.getAction()){
        case MotionEvent.ACTION_DOWN:
            //将按下时的坐标存储
            downX = x;
            downY = y;
            break;
        case MotionEvent.ACTION_MOVE:

            float dx= x-downX;
            float dy = y-downY;
            //slide orientation 
            int orientation = getOrientation(dx, dy);
            switch (orientation) {
                //tab Suction top , Sliding events should be referred to external RecyclerView processing.it is not work! Lift up your fingers and slide up again.
                case top:
                    if(!canScrollVertically(1) && isStick){
                        setNeedIntercept(false);
                    }else{
                        setNeedIntercept(true);
                    }
                    break;

                case right:
                    setNeedIntercept(false);
                    break;

                case left:
                    setNeedIntercept(false);
                    break;
            }
            return isNeedIntercept;
    }
    return super.onInterceptTouchEvent(e);
}

0 个答案:

没有答案