1、ScrollView嵌套Viewpager解决滑动冲突:
(1)重新ScrollView(法一)
/**
|
(2)重新ScrollView(法二)
public class MyScrollView extends ScrollView { private boolean canScroll; private GestureDetector mGestureDetector; View.OnTouchListener mGestureListener; public MyScrollView(Context context, AttributeSet attrs) { super(context, attrs); mGestureDetector = new GestureDetector(new YScrollDetector()); canScroll = true; } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if(ev.getAction() == MotionEvent.ACTION_UP) canScroll = true; return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev); } class YScrollDetector extends SimpleOnGestureListener { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if(canScroll) if (Math.abs(distanceY) >= Math.abs(distanceX)) canScroll = true; else canScroll = false; return canScroll; } } } |
个人是用第一个方法解决的,根据不同的情况可以自己处理!
注:本文仅代码都是网上找的,本文仅作记录而已!