需求:
一个ViewPager中包含三个Fragment;
每个fragment中都是一个RecyclerView的纵向列表;
列表中有的Item为可横向滑动的类似相册浏览的RecyclerView.
要求:在横向滑动相册浏览的RecyclerView时,Viewpager不会随着一起滑动.
分析:
直接写代码是不会存在什么滑动冲突的,但是有个问题是当横向的相册RecyclerView滑动到最左(或最右)时,再向左(或者右)滑动,viewpager就会拦截滑动事件,导致viewpager开始向左边的Item滑动.
既然ViewPager会拦截事件,看onIntercepterTouchEvent方法的代码可以知道,在MotionEvent.ACTION_MOVE中会调用
if (dx != 0 && !isGutterDrag(mLastMotionX, dx)
&& canScroll(this, false, (int) dx, (int) x, (int) y)) {
// Nested view has scrollable area under this point. Let it be handled there.