你想要的下拉刷新和上拉加載框架

screenshot

Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
Step 2. Add the dependency

    dependencies {
            compile 'com.github.yanjiabin:DDPullToRefresh-master:v1.0'
    }

in your xml

    <?xml version="1.0" encoding="utf-8"?>
    <com.yanjiubin.pulltorefreshlibrary.RefreshLayout
        android:id="@+id/refresh_layout"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- 當然這裏我使用的是recyecleview -->
        <android.support.v7.widget.RecyclerView
        android:id="@+id/recycleview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    </com.yanjiubin.pulltorefreshlibrary.RefreshLayout>

in your code

     refreshLayout = (RefreshLayout) findViewById(R.id.refresh_layout);
        mRecyclerView = (RecyclerView) findViewById(R.id.recycleview);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setNestedScrollingEnabled(false);
        mAdapter = new TextAdapter();
        mRecyclerView.setAdapter(mAdapter);
        //美團的效果就是new MeiTuanSelfHeaderViewManager(this),基本的下拉效果new NormalSelfHeaderViewManager(this)
        refreshLayout.setSelfHeaderViewManager(new MeiTuanSelfHeaderViewManager(this));
        pageLimitDelegate.attach(refreshLayout, mRecyclerView, mAdapter); //pageLimitDelegate  這個是一個分頁管理類

需要注意的是

這裏的上拉加載我使用的是 BaseRecyclerViewAdapterHelper 這個庫,個人感覺挺不錯的,我開發的項目中也都是用的這個庫,挺實用的,推薦給大家.
recycleView 搭配BaseRecyclerViewAdapterHelper可以基本上可以解決所有的列表展示.下拉刷新的和上拉加載的邏輯都封裝在了pageLimitDelegate這個分頁管理類中, 我們只需要請求數據的類 implements PageLimitDelegate.DataProvider 就行了 然後在重寫的 loadData(int page) 中去請求數據.

點擊這裏是我的github地址,如果喜歡不妨來個star

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章