標籤:cte inter blog ase des detail tap 釋放 開始
PullToRefreshScrollView 自訂下拉重新整理動畫,只需改一處。
以下部分轉載自http://blog.csdn.net/superjunjin/article/details/45022595
一,定義重新整理動畫的layout
在library下的com.handmark.pulltorefresh.library.internal包中的FlipLoadingLayout和RotateLoadingLayout
FlipLoadingLayout為ios風格的箭頭顛倒的重新整理動畫
RotateLoadingLayout為android風格的圖片旋轉動畫
共同的設定方法是
1,getDefaultDrawableResId()
動畫預設圖片,可以替換為自己的圖片
2,refreshingImpl()
正在重新整理時的回調方法,可以設定開始動畫
3,resetImpl()
重設
二,正在重新整理時為圖片置中旋轉的效果
1,首先修改library中的pull_to_refresh_header_vertical.xml,去除文字的layout,圖片layout水平置中
<?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,去除LoadingLayout中的關於textview的代碼
3,可以在RotateLoadingLayout中的getDefaultDrawableResId()方法替換成自己的圖片
三,設定自訂動畫效果
1,首先設定一個簡單的小人走的動畫效果,在anim檔案夾下建立一個xml,需要載入兩張圖片,控製圖片的停留時間
<?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="150"/> <item android:drawable="@drawable/app_loading1" android:duration="150"/> </animation-list>
2,建立重新整理動畫的layout,TweenAnimLoadingLayout,類似於之前的源碼中的FlipLoadingLayout和RotateLoadingLayout
主要設定初始化,和那幾個關鍵方法就行
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 幀動畫載入布局 */ public class TweenAnimLoadingLayout extends LoadingLayout { private AnimationDrawable animationDrawable; public TweenAnimLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) { super(context, mode, scrollDirection, attrs); // 初始化 mHeaderImage.setImageResource(R.anim.loading); animationDrawable = (AnimationDrawable) mHeaderImage.getDrawable(); } // 預設圖片 @Override protected int getDefaultDrawableResId() { return R.drawable.app_loading0; } @Override protected void onLoadingDrawableSet(Drawable imageDrawable) { // NO-OP } @Override protected void onPullImpl(float scaleOfLayout) { // NO-OP } // 拖動以重新整理 @Override protected void pullToRefreshImpl() { // NO-OP } // 正在重新整理時回調 @Override protected void refreshingImpl() { // 播放幀動畫 animationDrawable.start(); } // 釋放以重新整理 @Override protected void releaseToRefreshImpl() { // NO-OP } // 重新設定 @Override protected void resetImpl() { mHeaderImage.setVisibility(View.VISIBLE); mHeaderImage.clearAnimation(); } }
3,替換之前的重新整理layout為TweenAnimLoadingLayout
找到library項目com.handmark.pulltorefresh.library包下的PullToRefreshListView,發現頭腳的layout用的都是LoadingLayout,找到頭腳layout的建立方法createLoadingLayout進入,在createLoadingLayout方法中再進入createLoadingLayout,找到最原始的建立動畫layout的地方,把預設的RotateLoadingLayout改成TweenAnimLoadingLayout就行了
在PullToRefreshBase類下,變為
//在最原始的地方把建立動畫layout換成TweenAnimLoadingLayout LoadingLayout createLoadingLayout(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,去除LoadingLayout中的關於textview的代碼
代碼下載 http://download.csdn.net/detail/superjunjin/8589827
Android PullToRrefresh 自訂下拉重新整理動畫 (listview、scrollview等)