美文网首页
RecyclerView进击版之类似ViewPage分页

RecyclerView进击版之类似ViewPage分页

作者: 苏坡坡要吃婆婆酥 | 来源:发表于2017-06-20 09:51 被阅读0次

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

    2808681-ccf96760a98fc52b.gif
    2808681-e7ccc07455379573.gif
    2808681-63de50a3a326a56c.gif

    图三实现代码:(使用到的类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;
    }
    });

    相关文章

      网友评论

          本文标题:RecyclerView进击版之类似ViewPage分页

          本文链接:https://www.haomeiwen.com/subject/xrloqxtx.html