最近项目中使用到了CoordinatorLayout这种布局方式,搭配RecycleView,实现起来比较简单,而且不用自己处理滑动事件,但是改为了ListView后发生了滑动冲突.
所以想到了以下解决方案:
1.使用事件分发,当ListView在Y轴滑动时,将事件交给CoordinatorLayout处理,无效!!!
2.取消ListView在Y轴的滑动,计算手指移动的距离,交给CoordinatorLayout来scroll,无效!!!
以上都不行,google了下,发现由于由于CoordinatorLayout实现NestedScrollingParent接口,RecycleView实现了NestedScrollingChild接口,所以就可以在NestedScrollingChildHelper的帮助下实现滑动联动,知道了原因这就简单了,让我们的LIstView实现NestedScrollingChild接口,查看下NestedScrollingChild接口的源码
**
* This interface should be implemented by {@link android.view.View View} subclasses that wish
* to support dispatching nested scrolling operations to a cooperating parent
* {@link android.view.ViewGroup ViewGroup}.
*
* <p>Classes implementing this interface should create a final instance of a
* {@link NestedScrollingChildHelper} as a field and delegate any View methods to the
* <code>NestedScrollingChildHelper</code&g