Recycler实现上拉刷新 下拉加载

<com.scwang.smartrefresh.layout.SmartRefreshLayout
    android:id="@+id/Main_Refresh"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/Main_Recycler"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </FrameLayout>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
        mMainRefresh.setDefaultRefreshHeaderCreater(new DefaultRefreshHeaderCreater() {
            @Override
            public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
                layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);
                return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Translate);
            }
        });
        mMainRefresh.setDefaultRefreshFooterCreater(new DefaultRefreshFooterCreater() {
            @Override
            public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) {
                return new ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Translate);
            }
        });
        mMainRefresh.setOnRefreshLoadmoreListener(new OnRefreshLoadmoreListener() {
            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {
                initData();
                refreshlayout.finishLoadmore(2000);
            }

            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                count = 0;
                mList.clear();
                initData();
                refreshlayout.finishRefresh(2000);
            }
        });

猜你喜欢

转载自blog.csdn.net/a821265960/article/details/79717967