先图为敬。注:本文纯使用说明,具体剖析详见原主:
简:http://www.jianshu.com/p/3fe949083029
GitHub: https://github.com/zhuguohui/HorizontalPage



图三实现代码:(使用到的类PagingScrollHelper ,DividerItemDecoration)
注:此版本的RecyclerView需要25.0以上。
``
PagingScrollHelper scrollHelper = new PagingScrollHelper();
recyclerView.setAdapter(adapter);
scrollHelper.setUpRecycleView(recyclerView);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView.ItemDecoration itemDecoration = new DividerItemDecoration(this, LinearLayoutManager.HORIZONTAL);
RecyclerView.ItemDecoration lastItemDecoration = itemDecoration ;
recyclerView.setLayoutManager(layoutManager);
recyclerView.removeItemDecoration(lastItemDecoration);
recyclerView.addItemDecoration(itemDecoration);
scrollHelper.updateLayoutManger();
如若出现item需要双击才能点开的bug,修改PagingScrollHelper类中:
mAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
//回调监听
if (null != mOnPageChangeListener) {
mOnPageChangeListener.onPageChange(getPageIndex());
}
//修复双击item bug
mRecyclerView.stopScroll();
startY = offsetY;
startX = offsetX;
}
});
网友评论