android viewpaper嵌套viewpaper,滑动问题解决

两个viewpaper嵌套, 滑动会有冲突。 

解决方案:

自定义父对象。

public class MyViewPaper extends ViewPager {


public MyViewPaper(Context context, AttributeSet attrs) {
super(context, attrs);
}


protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
if (v != this && v instanceof ViewPager) {
int currentItem = ((ViewPager) v).getCurrentItem();
int countItem = ((ViewPager) v).getAdapter().getCount();
if ((currentItem == (countItem - 1) && dx < 0)
|| (currentItem == 0 && dx > 0)) {
return false;
}
return true;
}
return super.canScroll(v, checkV, dx, x, y);
}
}

你可能感兴趣的:(android)