美文网首页
NestedScrollView+tablayout+vierp

NestedScrollView+tablayout+vierp

作者: 小婷android | 来源:发表于2018-05-09 10:08 被阅读0次

    解决:在自定义的view中(view继承NestedScrollView)的onInterceptTouchEvent()方法做如下操作

    @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
    
            switch (ev.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    xDistance = yDistance = 0f;
                    xLast = ev.getX();
                    yLast = ev.getY();
                    break;
                case MotionEvent.ACTION_MOVE:
                    final float curX = ev.getX();
                    final float curY = ev.getY();
    
                    xDistance += Math.abs(curX - xLast);
                    yDistance += Math.abs(curY - yLast);
                    xLast = curX;
                    yLast = curY;
                    Log.e("SiberiaDante", "xDistance :" + xDistance + "---yDistance:" + yDistance);
                    if (isNeedScroll) {
                        if (xDistance == yDistance) {//点击不拦截
                            return false;
                        }
                        if (xDistance>yDistance){//左右滑动不拦截
                            return false;
                        }
                        if (xDistance<yDistance){//上下滑动拦截
                            return true;
                        }
                    }else{
                        return false;
                    }
    //                return !(xDistance > yDistance || yDistance < scaledTouchSlop) && isNeedScroll;
    
            }
    
            return super.onInterceptTouchEvent(ev);
        }
    
    

    相关文章

      网友评论

          本文标题:NestedScrollView+tablayout+vierp

          本文链接:https://www.haomeiwen.com/subject/grcnrftx.html