mViewPager.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
mViewPager.getParent().requestDisallowInterceptTouchEvent(true);
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
mViewPager.getParent().requestDisallowInterceptTouchEvent(true);
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
有时候在滑动VIewPager的时候触发onClick事件。这时候需要注释掉
mPager.getParent().requestDisallowInterceptTouchEvent(true);