看了下网上的资料,你们干嘛搞辣么辣么的复杂
就下面的代码可以搞定
重写下内层viewpager的ontouchevent方法
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_MOVE:
getParent().requestDisallowInterceptTouchEvent(true);
int position = this.getCurrentItem();
if(position==1){
this.setCurrentItem(0);//这个地方的显示有些突然,因为是跳转,不是滑动,可以设置滑动一定的距离再来跳转,或者大家有其他好办法请不吝赐教哦,多谢~
}
break;
case MotionEvent.ACTION_UP:
break;
default:
break;
}
本文提供了一种简化的方法来处理ViewPager的页面切换逻辑。通过重写onTouchEvent方法并针对ACTION_DOWN和ACTION_MOVE事件进行处理,可以有效地控制ViewPager的行为。当滑动到特定位置时,能够强制跳转到另一个页面。
500

被折叠的 条评论
为什么被折叠?



