这篇博文继续带来RecyclerView的用法,查看过RecyclerView的源码可以看到,RecyclerView继承了 NestedScollingChild接口。这个接口配合NestedScrollingParent使用,可以实现非常好的效果。
简单的说这两个接口是为了实现复杂的布局的,轻松实现子View与父View之间的嵌套滑动,今天主要讲下,NestedScrollingParent接口,因为,RecyclerView已经帮我们处理的NestedScrollingChild接口的逻辑。
直接看代码,主要有几个方法
onStartNestedScroll、onNestedScrollAccepted、onNestedPreScroll、onNestedScroll、onStopNestedScroll
这个是接口的主要实现方法,主要就是 onNestedPreScroll这个方法,来处理父View的逻辑,简单的说就是,父View处理父View的滑动逻辑,然后剩下来的滑动,交给子view处理。下面我直接贴出自定义的LinearLayout
public class StickyNavLayout2 extends LinearLayout implements NestedScrollingParent{
private int topHeight=50;
OverScroller mScroller;
private View topview;
private ViewPager mViewPager;
private Context context;
public Sti