当内部Viewpager滑动到最后时再滑动会滑动父级的ViewPager,此时我们需要重写ViewPager让控件滑动冲突解决
//作为子控件
private PointF curr,down;
@Override
public boolean onTouchEvent(MotionEvent ev) {
curr.x= ev.getX();
curr.y= ev.getY();
switch (ev.getAction())
{
case MotionEvent.ACTION_DOWN:
down.x=ev.getX();
down.y=ev.getY();
case MotionEvent.ACTION_MOVE:
getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
getParent().requestDisallowInterceptTouchEvent(false);
if(curr.x==down.x && curr.y==down.y)
{
return true;
}
break;
}
return super.onTouchEvent(ev);
}
2.
//作为父控件,是否允许滚动
@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
//验证当前可以滚动的控件不是当前控件并且也是一个ViewPager
if(v!=this && v instanceof ViewPager)
{
return true;
}
return super.canScroll(v, checkV, dx, x, y);
}