1. 简介
先看看英文介绍
/**
* Class intended to support snapping for a {@link RecyclerView}.
* <p>
* SnapHelper tries to handle fling as well but for this to work properly, the
* {@link RecyclerView.LayoutManager} must implement the {@link ScrollVectorProvider} interface or
* you should override {@link #onFling(int, int)} and handle fling manually.
*/
可以看出SnapHelper是对RecyclerView的一种拓展功能,支持snapping。SnapHelper通过处理RecyclerView的fling,来达到要展示的效果,但是这需要一个前提条件,就是RecyclerView的LayoutManager必须实现ScrollVectorProvider接口或者手动实现onFling接口,自己实现fling处理。
SnapHelper的实现原理是监听RecyclerView.OnFlingListener中的onFling接口。LinearSnapHelper&PagerSnapHelper是抽象类SnapHelper的具体实现。
区别在于: