Objective
Some time ago need to use to Recyclerview, just want to find a package of good drop-down refresh, pull the load of the library, the results Leng did not find, they wrote a.
Note: I'm talking about "pull up", not sliding to the bottom of the load automatically. Although now automatic loading is the mainstream and trend, but also do not rule out sometimes need to use the pull load ah, after all, the forest big, what kind of product managers have right.
After the code is written, ready to release to the Bintray, to ask colleagues the name of the project, colleagues said: "It is called dztrecyclerview!" puzzled, colleagues explained: "Fry the sky recyclerview! "What cool luxury has the connotation!! So, this library is called Wzmrecyclerview, well, initials on it, after all, not worthy of the name Dzt.
This article first describes how to use this recyclerview, and then if I do not have an outbreak of lazy cancer, and then detailed the implementation of the project in turn.
All right, get to the point.
Brief introduction
Wzmrecyclerview is an integrated drop-down refresh, pull load, sliding to the bottom of the automatic loading, add delete head tail four main features of the Recyclerview, of course, also supports the custom refresh the head and load the bottom, Emptyview, Loadingview, After the encapsulation of the simple and Easy-to-use adapter, encapsulation of the easy to use the split line.
The following are described in turn:
1. Add Delete head tail and click event
2. Drop down Refresh
3. Pull Up loading
4. Slide to bottom auto load
5. Use a custom Drop-down to flush the head
6. Use a custom pull up load tail
7. Use a custom automatic loading tail
Since this project has four main functions, I am not using all the integration in a recyclerview way, but in succession to implement each function in turn. The inheritance relationship is as follows:
Headerandfooterrecyclerview–> pulltorefreshrecyclerview–> Pulltoloadrecyclerview, And Autoloadrecyclerview also inherited from Pulltorefreshrecyclerview.
Therefore, if you ask me headerandfooterrecyclerview chicken not to pull down to refresh, it is certainly not chicken! But Pulltorefreshrecyclerview is a chicken to add a delete head to the tail.
Use
With this library, the students who use Android Studio will first have to add dependencies to the Build.gradle:
Compile ' com.mrw:wzmrecyclerview:1.0.2 '
Using Eclipse's classmates, you can clone the project on GitHub. Of course, the better way is to quickly switch to Android studio.
Add Delete head tail and click events
Headerandfooterrecyclerview.addheaderview (Headerview);//Add Head
Headerandfooterrecyclerview.removeheaderview ( Headerview);//delete head
Headerandfooterrecyclerview.addfooterview (Footerview);//Add Tail
Headerandfooterrecyclerview.removefooterview (Footerview);//delete tail
Headerandfooterrecyclerview.setonitemclicklistener (Onitemclicklistener Onitemclicklistener)//Add Item click event Monitor
Headerandfooterrecyclerview.setonitemlongclicklistener (Onitemlongclicklistener OnItemLongClickListener); Add Item Click event Monitor
Consistent with the usage of the ListView, it is not explained in detail. Effect Chart:
Head tail
Grid Head Tail
Staggred Head Tail
Drop down Refresh
Drop-down refreshes are available directly using Pulltorefreshrecyclerview, and here are a few ways to do this:
Pulltorefreshrecyclerview.setonrefreshlistener (Onrefreshlistener Onrefreshlistener);//Add Drop-down Refresh Monitor
Pulltorefreshrecyclerview.setrefreshviewcreator (Refreshheadercreator refreshheadercreator);//Use a custom drop-down to flush the head
Pulltorefreshrecyclerview.setrefreshenable (Boolean refreshenable),//dropdown refresh available
Pulltorefreshrecyclerview.setpullratio (float pullratio)//Set down damping coefficient
Pulltorefreshrecyclerview.completerefresh ()//Complete Refresh
The general use of the process, the use of Setonrefreshlistener listening to the Drop-down refresh, and then the refresh is completed after the call Completerefresh method to complete the refresh.
Pull up load
Pull load using Pulltoloadrecyclerview, the following methods are provided:
Pulltoloadrecyclerview.setonloadlistener (Onloadlistener Onloadlistener)//Add pull up load monitor
Pulltoloadrecyclerview.setloadviewcreator (Loadfootercreator loadviewcreator);//Use a custom pull to load the tail
Pulltoloadrecyclerview.setloadenable (Boolean loadmoreenable),//Pull up loading is available
Pulltoloadrecyclerview.setpullloadratio (float loadratio)//Set up damping coefficient
pulltoloadrecyclerview.completeload (); /Complete Loading
The general use of the process, the use of Setonloadlistener listening to pull up loading, and then load completed after the call Completeload method to complete the load on it.
Note: LayoutManager recommended to use Wzmlinearlayoutmanager and Wzmgridlayoutmanager in the pull load, as the reason will be explained in later articles.
Effect Chart:
Refresh Load
Grid Refresh Load
staggred Refresh Load
Slide to bottom auto load
Automatic loading using Autoloadrecyclerview provides the following methods:
Autoloadrecyclerview.setonloadlistener (Onloadlistener Onloadlistener);//Add Load Monitor
Autoloadrecyclerview.setautoloadviewcreator (Autoloadfootercreator autoloadfootercreator);//Use a custom automatically loaded tail
Autoloadrecyclerview.completeload ()//completes Loading
Autoloadrecyclerview.setnomore (Boolean nomore);/Set no more data
The general use of the process, the use of setonloadlistener monitoring automatic loading, and then load completed after the call Completeload method to complete the load, when there is no more data, call the Setnomore method.
Effect Chart:
Grid Auto Load
Use a custom Drop-down to flush the head
All items that do not support custom refresh load view are bullying, so we support a custom flush head and load tail. Does this sentence have the feeling of old Luo?
The Custom dropdown flush head is actually very simple, if you look at the above dropdown refresh introduction, you will find a way:
Pulltorefreshrecyclerview.setrefreshviewcreator (Refreshheadercreator refreshheadercreator);//Use a custom drop-down to flush the head
Yes, this is the way to set up a custom Drop-down refresh head, what is this refreshheadercreator? In fact, it is an abstract class, you just inherit it to implement the abstract method, it has three methods to implement:
/** * Dropdown
* @param distance distance
* @return Drop distance, returns true to continue down pull
/public
abstract Boolean onstartpull ( float distance, int laststate);
/**
* Let
go refresh * @param distance distance
* @return Drop distance, return True to indicate that you can continue the Drop-down */public
Abstract Boolean Onreleasetorefresh (float distance,int laststate);
/** begins refreshing
/public abstract void onstartrefreshing ();
/** Refresh End *
/public abstract void Onstoprefresh ();
Is it easy to fry chicken?
Inherit Refreshheadercreator
Calling the Setrefreshviewcreator method
No more.
The Onstartpull method refers to the drop down process, passing in two parameters: one distance (distance) and the last state (LastState). Distance allows you to complete the animation of your own dropdown head according to the distance, LastState lets you know "drop down refresh", "Let go immediately refresh" two state switch.
Onreleasetorefresh and Onstartpull are the same.
To load the tail with a custom pull
This is actually the same as the custom Drop-down flush head,
Pulltoloadrecyclerview.setloadviewcreator (Loadfootercreator loadviewcreator);//Use a custom pull to load the tail
Take a look at this loadfootercreator:
/** *
Pull
* @param distance distance
* @return Whether to continue the pull
/protected abstract Boolean onstartpull (float Distance,int laststate);
/**
* Drop load
* @param distance distance
* @return Whether to continue the
pull
/protected abstract Boolean onreleasetoload ( float distance,int laststate);
/** Start loading
/protected abstract void onstartloading ();
/** Loading End * *
protected abstract void onstopload ();
Oh, like a refreshheadercreator, that's not to say.
Use a custom auto load tail
Still the same:
Autoloadrecyclerview.setautoloadviewcreator (Autoloadfootercreator autoloadfootercreator);//Use a custom automatically loaded tail
Look at Autoloadfootercreator:
/***
* Get footer * *
protected abstract View getloadview (context, Recyclerview recyclerview);
/***
* No More * *
protected abstract View getnomoreview (context Context,recyclerview Recyclerview);
Well, it's simpler, two ways to get the tail in the load, no more tail.
So easy!!
Postscript
After that, I'll take the time to make a detailed introduction to the project's implementation process.
Source Address: Https://github.com/whichname/WZMRecyclerView