Reference from http://blog.csdn.net/wwj_748/article/details/42523611
First, download the famous refresh Framework Https://github.com/chrisbanes/Android-PullToRefresh, where simple is demo,library and extras as a project package into simple
First, define the layout of the Refresh animation
Fliploadinglayout and Rotateloadinglayout in the Com.handmark.pulltorefresh.library.internal package under the library
Fliploadinglayout Refresh animations for iOS-style arrows upside down
Rotateloadinglayout Animation for Android-style pictures
The common set-up method is
1,getdefaultdrawableresid ()
Animated default picture, can be replaced with your own picture
2,refreshingimpl ()
callback method that is being refreshed, you can set the start animation
3,resetimpl ()
Reset
Second, the effect of centering the picture when it is being refreshed
1, first modify the Pull_to_refresh_header_vertical.xml in the library, remove the layout of the text, Picture layout Horizontal Center
<?xml version= "1.0" encoding= "Utf-8"? ><merge xmlns:android= "Http://schemas.android.com/apk/res/android" > <framelayout android:id= "@+id/fl_inner" android:layout_width= "Fill_parent" Android:layout_ height= "Wrap_content" android:paddingbottom= "@dimen/header_footer_top_bottom_padding" android:paddingleft= "@ Dimen/header_footer_left_right_padding "android:paddingright=" @dimen/header_footer_left_right_padding "Andro id:paddingtop= "@dimen/header_footer_top_bottom_padding" > <framelayout android:layout_width= "wrap_ Content "android:layout_height=" wrap_content "android:layout_gravity=" Center_horizontal "> <imageview android:id= "@+id/pull_to_refresh_image" android:layout_width= "Wrap_conten T "android:layout_height=" wrap_content "android:layout_gravity=" center "/> < ; ProgressBar AndroId:id= "@+id/pull_to_refresh_progress" style= "Android:attr/progressbarstylesmall" Android:la Yout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_gravity= "Cente R "Android:indeterminate=" true "android:visibility=" Gone "/> </FrameLayout> <!--<linearlayout android:layout_width= "wrap_content" android:layout_height= "Wrap_cont ENT "android:layout_gravity=" center "android:gravity=" Center_horizontal "Android:orientat ion= "vertical" > <textview android:id= "@+id/pull_to_refresh_text" android:l Ayout_width= "Wrap_content" android:layout_height= "Wrap_content" android:singleline= "true" Android:textappearance= "? Android:attr/textappearance" android:textstyle= "bold"/> <textview Android:id= "@+id/pull_to_refresh_sub_text" android:layout_width= "Wrap_content" Android : layout_height= "Wrap_content" android:singleline= "true" android:textappearance= "? Android:att R/textappearancesmall "android:visibility=" Gone "/> </LinearLayout> </framelay Out></merge>
2, remove the code about TextView in Loadinglayout
Third, set the custom animation effect
1, first set a simple villain walking animation effect , in the Anim folder to create a new XML, need to load two pictures, control the picture's dwell time
<?xml version= "1.0" encoding= "Utf-8"?> <animation-list xmlns:android= "http://schemas.android.com/apk /res/android " android:oneshot=" false "> <item android:drawable=" @drawable/app_loading0 " android:duration= "/> <item android:drawable=" @drawable/app_loading1 " android:duration = "/>" </animation-list>
2, new refresh animation layout,Tweenanimloadinglayout, similar to the previous source in the Fliploadinglayout and Rotateloadinglayout
The main settings are initialized, and those are the key methods of the line
Package Com.handmark.pulltorefresh.library.internal;import Com.handmark.pulltorefresh.library.r;import Com.handmark.pulltorefresh.library.pulltorefreshbase.mode;import Com.handmark.pulltorefresh.library.pulltorefreshbase.orientation;import Android.content.context;import Android.content.res.typedarray;import Android.graphics.drawable.animationdrawable;import Android.graphics.drawable.drawable;import android.view.view;/** * @date 2015/1/8 * @author Wuwenjie * @desc frame animation load Layout */pub Lic class Tweenanimloadinglayout extends Loadinglayout {private animationdrawable Animationdrawable;public Tweenanimloadinglayout (context context, mode mode,orientation scrolldirection, TypedArray attrs) {Super (context, mode, Scrolldirection, attrs);//Initialize Mheaderimage.setimageresource (r.anim.loading); animationdrawable = (animationDrawable ) mheaderimage.getdrawable ();} Default picture @overrideprotected int Getdefaultdrawableresid () {return R.DRAWABLE.APP_LOADING0;} @Overrideprotected void Onloadingdrawableset (drawable imagedrawable) {//no-op} @Overrideprotected void Onpullimpl (float scaleoflayout) {//no-op}//drop-down to refresh @overrideprotected void Pulltorefreshimpl () {///no-op}//callback @overrideprotected void Refreshingimpl () {//Play frame animation Animationdrawable.start ();} Release to refresh @overrideprotected void Releasetorefreshimpl () {///no-op}//reset @overrideprotected void Resetimpl () { Mheaderimage.setvisibility (view.visible); Mheaderimage.clearanimation ();}}
3,
replace the previous refresh layout to Tweenanimloadinglayout
Find the Library project under the Com.handmark.pulltorefresh.library package of Pulltorefreshlistview, found that the layout of the head foot is loadinglayout, find the way to create the first foot layout Createl Oadinglayout enter, in the Createloadinglayout method again into the Createloadinglayout, find the most original new animation layout of the place, You can change the default rotateloadinglayout to Tweenanimloadinglayout.
Under the Pulltorefreshbase class, change to
Change the new animation layout to Tweenanimloadinglayoutloadinglayout Createloadinglayout in the most primitive places (context context, Mode mode, Orientation scrolldirection, TypedArray attrs) {switch (this) {case Rotate:default://return new Rotateloadinglayout ( Context, mode, scrolldirection, attrs); return new Tweenanimloadinglayout (context, mode, scrolldirection, attrs); case Flip:return new Fliploadinglayout (context, mode, scrolldirection, attrs);}
4, remove the code about TextView in Loadinglayout
code Download http://download.csdn.net/detail/superjunjin/8589827
Pulltorrefresh Customizing the drop-down refresh animation