Giter VIP home page Giter VIP logo

nestedrecyclerview-1's Introduction

RecyclerView嵌套ViewPager嵌套RecyclerView

====

NestedRecyclerView

功能描述

  1. 支持嵌套ViewPager嵌套RecyclerView,理论上也支持直接嵌套RecyclerView,不过感觉没什么意义,就不再提供demo

  2. 一个NestedRecyclerView类处理所有滚动逻辑,不需要对ViewPager内的RecyclerView做特殊处理

  3. 支持第三方的下拉刷新库,例如SmartRefreshLayout

  4. 提供RecyclerView内的tab栏吸顶【适合简单的吸顶,以及不可操作动画吸顶,如京东app】 以及 外部传入吸顶tab栏【适合需要动态改变吸顶tab高度的场景,例如吸顶广告,可操作的吸顶栏动画,或者 吸顶栏位置有特殊要求等】 两种方式实现吸顶,具体见demo,暂不提供动画相关demo,以后看情况添加

  5. 提供底部视图缓存demo,避免滑出ViewPager时卡顿的问题

带广告的tab示例

demo.gif

使用方法

新增依赖

  1. 在项目的根目录gradle新增仓库如下:
allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}
  1. 使用module依赖,新增依赖:
 implementation 'com.github.liyuzero:NestedRecyclerView:1.0'

具体调用(详情见demo)

  1. 布局,当做普通RecyclerView进行布局即可
        <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
        
                <com.yu.nested.library.NestedParentRecyclerView
                    android:id="@+id/recyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>
        
            </FrameLayout>

  1. 初始化
        final NestedRecyclerView mNestedRecyclerView = view.findViewById(R.id.recyclerView);
        //recyclerView正常初始化
        mNestedRecyclerView.setLayoutManager(new LinearLayoutManager(mNestedRecyclerView.getContext()));
        
        //底部tab栏 和 ViewPager
        BottomTabView tabView = new BottomTabView(getContext());
        //设置底部Tab View大小,必须!!!!!!!!!!!, 该高度一般等于NestedRecyclerView大小
        mNestedRecyclerView.post(new Runnable() {
            @Override
            public void run() {
                mBottomTabView.setViewHeight(mNestedRecyclerView.getMeasuredHeight());
            }
        });

        mNestedRecyclerView.setAdapter(new RecyclerView.Adapter() {
            if(viewType == 1) {
                //一般是最后一个view是底部tab栏以及ViewPager
                return new RecyclerView.ViewHolder(mBottomTabView) {
                
                };
            } else {
                TextView titleView = new TextView(parent.getContext());
                ....
            }
            
            
        });

        //初始化,返回值为当前 ViewPager内部 展示的 RecyclerView
        mNestedRecyclerView.setChildRecyclerViewHelper(new NestedRecyclerView.ChildRecyclerViewHelper() {
            @Override
            public RecyclerView getCurRecyclerView() {
                return mBottomTabView.getCurRecyclerView();
            }

            //提供外部自定义吸顶栏时需要实现的接口,方便实现各种自定义效果,例如广告展示,触摸动画等等
            public View getInnerTabView() {
                return null;
            }
    
            public View getOutTabView() {
                return null;
            }

        });
        //监听器
        mNestedRecyclerView.addOnActionListener(new NestedRecyclerView.OnActionListener() {
            @Override
            public void onTabMounting(boolean isMounting) {
                //吸顶状态监听
                if(isMounting) {
                    ToastUtil.INSTANCE.showToast(mNestedRecyclerView.getContext(), "吸顶了");
                }
            }

            @Override
            public void onTabViewFirstShow() {
                //tab栏首次展示出来,一般用作打点
            }
        });

nestedrecyclerview-1's People

Contributors

liyuzero avatar wpq2014 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.