Skip to content

常规的下拉刷新和上拉加载,同时还支持美团和饿了么的下拉刷新

Notifications You must be signed in to change notification settings

yanjiabin/DDPullToRefresh-master

Repository files navigation

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:https://schemas.android.com/apk/res/android"
	    xmlns:tools="http:https://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>
	 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) 中去请求数据.

About

常规的下拉刷新和上拉加载,同时还支持美团和饿了么的下拉刷新

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages