NestedScrollView+tablayout+vierp
2018-05-09 本文已影响0人
小婷android
解决:在自定义的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);
}