Android Pulltorrefresh Custom drop-down refresh animations (listview, ScrollView, etc.)

Source: Internet
Author: User

Pulltorefreshscrollview the custom drop-down to refresh the animation, just change one place.

The following sections are reproduced from http://blog.csdn.net/superjunjin/article/details/45022595

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"Android: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_content"Android:layout_height="wrap_content"android:layout_gravity="Center"/> <ProgressBar Android:id="@+id/pull_to_refresh_progress"style="? Android:attr/progressbarstylesmall"Android:layout_width="wrap_content"Android:layout_height="wrap_content"android:layout_gravity="Center"android:indeterminate="true"android:visibility="Gone"/> </FrameLayout> <!--<LinearLayout android:layout_width="wrap_content"Android:layout_height="wrap_content"android:layout_gravity="Center"android:gravity="Center_horizontal"android:orientation="Vertical"> <TextView Android:id="@+id/pull_to_refresh_text"Android:layout_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:attr/textappearancesmall"android:visibility="Gone"/> </LinearLayout> </FrameLayout></merge>

2, remove the code about TextView in Loadinglayout

3, you can replace the Getdefaultdrawableresid () method in rotateloadinglayout with your own picture

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=" Max"/> <Item Android:drawable="@drawable/app_loading1"android:duration=" Max"/> </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*/   Public classTweenanimloadinglayout extends Loadinglayout {Privateanimationdrawable animationdrawable;  PublicTweenanimloadinglayout (context context, mode mode, Orientation scrolldirection, TypedArray attrs) {          Super (context, mode, scrolldirection, attrs); //InitializeMheaderimage.setimageresource (r.anim.loading); Animationdrawable=(animationdrawable) mheaderimage.getdrawable (); }      //default Picture@Overrideprotected intGetdefaultdrawableresid () {returnR.DRAWABLE.APP_LOADING0; } @Overrideprotected voidOnloadingdrawableset (drawable imagedrawable) {//No-op} @Overrideprotected voidOnpullimpl (floatscaleoflayout) {          //No-op    }      //Drop-down to refresh@Overrideprotected voidPulltorefreshimpl () {//No-op    }      //callback when refreshing@Overrideprotected voidRefreshingimpl () {//Play Frame AnimationsAnimationdrawable.start (); }      //Release to refresh@Overrideprotected voidReleasetorefreshimpl () {//No-op    }      //re-set@Overrideprotected voidResetimpl () {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 tweenanimloadinglayout in the most primitive placeloadinglayout createloadinglayout (context context, mode mode, Orientation scrolldirection, TypedArray attrs) { Switch( This) {                   CaseROTATE:default:  //return new Rotateloadinglayout (context, mode, scrolldirection, attrs);                     return Newtweenanimloadinglayout (context, mode, scrolldirection, attrs);  CaseFLIP:return Newfliploadinglayout (context, mode, scrolldirection, attrs); }          }  

4, remove the code about TextView in Loadinglayout

code Download http://download.csdn.net/detail/superjunjin/8589827

Android Pulltorrefresh Custom drop-down refresh animations (listview, ScrollView, etc.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.