Viewpager q嵌套 viewPager ,左右滑动事件的冲突,外围的ViewPager要重写几个方法就可以了:
onTouchEvent,OnInterceptTouchEvent,在这两个方法中加入自定义样式,在使用的时候根据需要选择
使用系统自己的处理方法或者用户自定义的方式
public class MYViewPager extends ViewPager { private boolean swipeable; public MYViewPager(Context context, AttributeSet attrs) { super(context, attrs); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MYViewPager); swipeable = ta.getBoolean(R.styleable.MYViewPager_swipeable, true); ta.recycle(); } @SuppressLint("ClickableViewAccessibility") @Override public boolean onTouchEvent(MotionEvent event) { return swipeable ? super.onTouchEvent(event) : false; } @Override public boolean onInterceptTouchEvent(MotionEvent event) { return swipeable ? super.onInterceptTouchEvent(event) : false; } public boolean isSwipeable() { return swipeable; } public void setSwipeable(boolean swipeable) { this.swipeable = swipeable; } }
时间: 2024-10-12 07:46:59