First, write at the beginning of the words
The reason for writing this is because the project is useful, need to add a refresh stickylistheaders, in fact, is a framelayout inside a listview of the custom view layout, but some well-known refresh framework I tried to not support, Both Pulltorefresh and Xlistview have implemented a refreshed view of themselves, and then let's use the refreshed view directly to achieve the pull-down refresh. What I need is a framework that I tell him when he needs to refresh, which means that no matter what view, as long as you can tell the frame when you need to refresh, the framework can give you when to refresh, from this point of view, the framework is omnipotent, for all the view, He's the--xrefreshview I'm going to introduce next.
Two
GIF look on the effect may not be very good a bit Kaka, but on the real machine above, still quite smooth.
Third, simple usage
Xrefreshview at this stage of the default support Listview,gridview,webview, of course, can also support Scrollview,textview, but now did not add in, add in is also very simple.
For any view that you want to refresh, just set a layer of xrefreshview outside the view you want to refresh, just like this
<com.andview.refreshview.xrefreshview xmlns:android= "http://schemas.android.com/apk/res/android" xmlns: xrefreshview= "Http://schemas.android.com/apk/res-auto" xmlns:tools= "Http://schemas.android.com/tools " Android:id= "@+id/custom_view" android:layout_width= "match_parent" android:layout_height= "Match_parent" android:background= "#fff" android:orientation= "vertical" xrefreshview:isheightmatchparent= "true" xrefreshview:iswidthmatchparent= "true" > <listview android:id= "@+id/lv" android:layout _width= "Match_parent" android:layout_height= "wrap_content"/> <!--xmlns:xrefreshview= "/http Schemas.android.com/apk/res/com.andview.refreshview "--></com.andview.refreshview.xrefreshview>
The Xrefreshview tag is some of my custom properties
<declare-styleable name= "Xrefreshview" > <attr name= "Isheightmatchparent" format= "boolean"/> <attr name= "Iswidthmatchparent" format= "boolean"/> <attr name= "AutoRefresh" format= "boolean"/> </declare-styleable> <declare-styleable name= "Stickylistheaderslistview" >
Isheightmatchparent and iswidthmatchparent represent whether the height is full of parent, why do you need these two attributes?
Well, that's it, I'm doing stickylistheaders. When the refresh, I found that will drop frames, the situation of the lag. Later in the process of solving the problem, I found that the main time-consuming occurred in the onmeasure process, that is, the system in the measurement of the size of the view will consume too much time to lead to Kaka. Knowing where the problem is, we have to deal with him next. Obviously there are two options: 1, rewrite the stickylistheaders, make it more efficient when measuring, 2, find their own reasons. The first project cost a bit too much, so I was looking for my reasons, and later on the Internet to see such an article, the understanding of the Android View.onmeasure method
He mentions that when we set width or height to fill_parent, the measure method in which the container calls the child view in the layout is exactly because the child view occupies the space of the remaining container, so its size is deterministic, When set to Wrap_content, the container passes in At_most, indicating the maximum size of the child view . And then I had a look at my layout.
<com.andview.refreshview.xrefreshview xmlns:android= "http://schemas.android.com/apk/res/android" xmlns: xrefreshview= "Http://schemas.android.com/apk/res-auto" xmlns:tools= "Http://schemas.android.com/tools " Android:id= "@+id/custom_view" android:layout_width= "match_parent" android:layout_height= "Match_parent" android:background= "#fff" xrefreshview:autorefresh= "true" > < Com.example.xrefreshviewdemo.stickyListHeaders.StickyListHeadersListView android:id= "@+id/sticky_list" android:layout_width= "match_parent" android:layout_height= "wrap_content" /></ Com.andview.refreshview.xrefreshview>
Height is set to wrap_content, when I change to match_parent after the problem solved. I was thinking, maybe because the system is measuring, you tell the system a precise size, the system will be very happy, a happy efficiency is high.
So if you're using a more complex view and you're going to be stuck with a refresh, you might want to set the width to Match_parent, and Xrefreshview automatically do it for you, The default isheightmatchparent and Iswidthmatchparent are true. But if you have your own special needs, you can set them to false in the layout.
AutoRefresh refers to whether the view automatically refreshes when you first enter the page
3.1 Xrefreshview Default supported view
Next, for xrefreshview default supported view, this is required in Java code
Sets whether a pull-up refresh refreshview.setpullloadenable (true) is possible;
Set whether you can pull up refresh, default is not possible
Sets the type of Refresh View Refreshview.setrefreshviewtype (Xrefreshviewtype.abslistview);
To set the type of view to refresh, first look at the Xrefreshviewtype class
/** * Support pull-up refresh view * @author [email protected] * */public enum Xrefreshviewtype {noscrollview, Abslistview, SCROLLVIEW, W Ebview,none}
are non-scrollable view,abslistview,scrollview,webview and other
It is important to note that only the Xrefreshview default supported view needs to set the view type, but you do not need to set it if you are a custom view.
Sets whether Refreshview.setautorefresh (true) can be refreshed automatically;
Sets whether to refresh automatically, false by default. Here can also be configured in the XML, but the priority is higher in the Java code, that is, if the XML is configured to False, but the Java code is set to True, then the time will be automatically refreshed, but then again, who will be idle egg pain to do so.
public static long Lastrefreshtime;
Set the last Refresh Time Refreshview.restorelastrefreshtime (lastrefreshtime);
Set the time of the last refresh, here I first defined a static long type of constant, the reason is static is to let the program can keep his value unchanged, this is my lazy writing, if you really need to refresh the header above show how long before the refresh, you can save this value to local. Lastrefreshtime is the Xrefreshview return supply used for persistent storage, specifically in the code:
Refreshview.setxrefreshviewlistener (New Xrefreshviewlistener () {@Overridepublic void Onrefresh () {new Handler (). Postdelayed (New Runnable () {@Overridepublic void run () {Refreshview.stoprefresh (); lastrefreshtime = Refreshview.getlastrefreshtime ();}}, 2000);} @Overridepublic void Onloadmore () {new Handler (). postdelayed (New Runnable () {@Overridepublic void run () { Refreshview.stoploadmore ();}}, 2000);});
Here is really involved in the pull up and pull down to refresh this block, if you want to listen to refresh events, you need to register for monitoring, The method is Refreshview.setxrefreshviewlistener, the parameter is a flush listener interface Xrefreshviewlistener, where Onrefresh is the callback when the dropdown is refreshed, and Onloadmore will callback when the pull-up refreshes, you need to do This is where the refresh of the data is processed, and when the data refresh is complete, Xrefreshview provides Stoprefresh and Stoploadmore to stop the pull-down refresh and the UI to stop the pull-up refresh, respectively. In front of the lastrefreshtime, when the refresh is stopped, the refresh time will be passed to you by Getlastrefreshtime this method, you can do localized storage for the next use.
3.2 Customizing view
Support is also provided if you want to refresh your custom View,xrefreshview.
Refreshview.setrefreshbase (New Xrefreshcontentviewbase () {@Overridepublic Boolean istop () {return Stickylv.getfirstvisibleposition () = = 0;} @Overridepublic Boolean Isbottom () {return stickylv.getlastvisibleposition () = = MTotalItemCount-1;}});
Custom view needs to implement its own refresh rules to tell Xrefreshview when the custom view reached the top and when it reached the bottom. What do you think? is not very convenient! Xrefreshview only need you to provide custom view needs to refresh the time, everything else rest assured to Xrefreshview Bar, he will help you solve everything!
Next, Xrefreshview will throw the refreshed header and footer out so that you can define your own header and footer in the app.
Four
First, how to use, the next article will explain how the next xrefreshview is implemented.
If you're interested in Xrefreshview, you can focus on GitHub Xrefreshview
Of course you can also click here to download directly
If you have good suggestions, also welcome to contact me, you can directly on GitHub to push me, or contact me e-mail: [Email protected]
Build Android Magnum pull-up dropdown refresh frame--xrefreshview (i)