当父ViewPager嵌套子ViewPager时,子ViewPager滑到最后一页继续滑动时会导致父ViewPager滑动,为了让子ViewPager滑到最后一页时不能继续滑动,则重写父ViewPager:
public class ForbiddenScrollViewPager extends ViewPager {
public ForbiddenScrollViewPager(Context context) {
super(context);
}
public ForbiddenScrollViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
if (v != this && v instanceof ViewPager) {
return true;
}
return super.canScroll(v, checkV, dx, x, y);
}
}
原文地址:http://6169621.blog.51cto.com/6159621/1614487