1. 程式人生 > >PullToRefresh修改上拉下拉載入動畫

PullToRefresh修改上拉下拉載入動畫

修改PullTuRefreshListView原始碼:
實現 動畫載入:

第一步:

原始碼分析:

PullToRefrehListView 預設載入動畫是很難看的:
這裡寫圖片描述

預設是很難看的 但我們想要實現我們的效果怎麼辦?

分析原始碼:

找到PullRefreshListView 分析:

我們知道 上拉和下拉載入 動畫無非是 pullToRefreshListView 中添加了頭和腳, 而頭和腳都是動畫!!

PullToRefreshListView.java 兩個動畫類變數:

//定義  頭部和尾部的載入動畫
    private LoadingLayout mHeaderLoadingView;
    private LoadingLayout mFooterLoadingView;

...
//載入佈局 @Override protected LoadingLayoutProxy createLoadingLayoutProxy(final boolean includeStart, final boolean includeEnd) { LoadingLayoutProxy proxy = super.createLoadingLayoutProxy(includeStart, includeEnd); if (mListViewExtrasEnabled) { final Mode mode = getMode(); if
(includeStart && mode.showHeaderLoadingLayout()) { //新增 頭部動畫 到listView中 proxy.addLayout(mHeaderLoadingView); } if (includeEnd && mode.showFooterLoadingLayout()) { //新增 新增腳部動畫 到listView中 proxy.addLayout(mFooterLoadingView); } } return
proxy; } ...

createLoadingLayoutProxy方法繼承自抽象類PullToRefreshAdapterViewBase檢視方法沒有該方法繼續父類查詢,查詢PullToRefreshAdapterViewBase父類PullToRefreshBase:


// We need to create now layouts now
        mHeaderLayout = createLoadingLayout(context, Mode.PULL_FROM_START, a);
        mFooterLayout = createLoadingLayout(context, Mode.PULL_FROM_END, a);

...


//載入動畫    佈局----------
    protected LoadingLayout createLoadingLayout(Context context, Mode mode, TypedArray attrs) {
        LoadingLayout layout = mLoadingAnimationStyle.createLoadingLayout(context, mode,
                getPullToRefreshScrollDirection(), attrs);
        layout.setVisibility(View.INVISIBLE);
        return layout;
    }

...

//此處實現了我們需要  修改的動畫方法:
//修改程式碼實現  自己的下載重新整理動畫
        LoadingLayout createLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
            switch (this) {
                case ROTATE://旋轉動畫
                default:

                //幀動畫   frameAnimationLayout為     自定義動畫類
                    return new FrameAnimationLayout(context, mode, scrollDirection, attrs);

                //旋轉動畫   預設的動畫
//                  return new RotateLoadingLayout(context, mode, scrollDirection, attrs);


                case FLIP:
                    return new FlipLoadingLayout(context, mode, scrollDirection, attrs);
            }
        }

//自定義動畫類 實現動畫

package com.handmark.pulltorefresh.library.internal;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.R;

/**
 * Package_name:com.handmark.pulltorefresh.library.internal
 * Author:zhaoQiang
 * Email:[email protected]
 * Date:2016/11/28  19:34
 *
 * 幀動畫  實現載入自定義的動畫   實現的是幀動畫
 */
public class FrameAnimationLayout extends LoadingLayout{
//繼承自 PullToRefreshListView提供的loadingLayout類

    private AnimationDrawable mAnimationDrawable;

    public FrameAnimationLayout(Context context, PullToRefreshBase.Mode mode,
                                PullToRefreshBase.Orientation scrollDirection, TypedArray attrs) {
        super(context, mode, scrollDirection, attrs);
        mHeaderImage.setImageResource(R.drawable.ptr_animation);
        mAnimationDrawable = (AnimationDrawable) mHeaderImage.getDrawable();
    }

    @Override
    protected int getDefaultDrawableResId() {
    //返回   自定義動畫布局
        return R.drawable.ptr_animation;
    }

    @Override
    protected void onLoadingDrawableSet(Drawable imageDrawable) {

    }

    @Override
    protected void onPullImpl(float scaleOfLayout) {

    }

    @Override
    protected void pullToRefreshImpl() {

    }

    //重新整理的時候
    @Override
    protected void refreshingImpl() {
        mAnimationDrawable.start();//開啟動畫
    }

    @Override
    protected void releaseToRefreshImpl() {

    }

    @Override
    protected void resetImpl() {

    }
}

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/ptr_img_0" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_1" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_2" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_3" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_4" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_5" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_6" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_7" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_8" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_9" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_10" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_11" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_12" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_13" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_14" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_15" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_16" android:duration="10"></item>
    <item android:drawable="@drawable/ptr_img_17" android:duration="10"></item>


</animation-list>

這就完成了自定義下拉和上拉動畫,修改部分原始碼以及自定義幀動畫類,效果圖:這裡寫圖片描述

參考部落格:

相關推薦

PullToRefresh修改載入動畫

修改PullTuRefreshListView原始碼: 實現 動畫載入: 第一步: 原始碼分析: PullToRefrehListView 預設載入動畫是很難看的: 預設是很難看的 但我們想要實現我們的效果怎麼辦? 分析原始碼: 找

XListView載入 DrawerLayout側

1.佈局 <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android=“http://schemas.android.com/apk/res/a

Xlistview+多條目+重新整理載入+側滑

** MainActivity頁面 ** package com.example.lx_module.activity; import android.os.Bundle; import android.support.annotation.NonNull; import an

XListView多條目載入沒有,

activity_main <com.bwie.xlistview.XListView android:id="@+id/lv_news" android:layout_width="match_parent" android:la

關於在jquery中使用iscorll實現載入重新整理的方法

實現原理是:判斷fiiptop,flipdown是否顯示為依據myScroll = new iScroll('wraphome', { fixedScrollbar: true, hideScrollbar:

Jquery 判斷滾動條到達頂部或底部 (可用於載入重新整理)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//D

pullToRefresh使用(實現listview)

使用pullToRefresh: 1.pullToRefresh的匯入 在https://github.com/chrisbanes/Android-PullToRefresh 下載pullToRefresh 的開原始檔 Android-PullToRef

小程序共存時不可使用scroll-view的解決方法

下拉 text2 data nbsp css 必須 scroll wid 解決 使用 bindscrolltolower ,必須搭配使用的 scroll-view 會導致小程序 "enablePullDownRefresh": true 下拉不能使用。 解決方法,就是當兩者

自定義ScrollView 實現的回彈效果--並且子控件中有Viewpager的情況

是否 AS abs pri tar utils lda animation ted onInterceptTouchEvent就是對子控件中Viewpager的處理:左右滑動應該讓viewpager消費 1 public class MyScrollView ext

Jquery 判斷滾動條到達頂部或底部 (可用於加載刷新)

ready UNC 判斷 獲取 scrip () ext 上拉 fun <script type="text/javascript"> $(document).ready(function() { $(window).scroll(fun

git從碼雲時的問題

pos 圖片 登陸 epo 原因 there 下拉 art 選中 再登陸後自己從碼雲上往下下載時出現 as報錯 ******.is registered as a Git root, but no Git repositories were found there. 原因:

private String path = "http://www.xieast.com/api/news/news.php?page="; private int index = 1; private XListView xlistview; private List<NewsB

springMVC搜尋時候的選和修改時候的選比較

寫法一:用於搜尋(下拉選的資料寫固定值) <sf:select path="status" value="" class="form-control">     <sf:option value="">請選擇</sf:option>

多條目一,+

//MainActivity package com.example.day08_test02; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.example

android之XListview,出現BUG

第一次發,不要吐槽哈 上拉載入若螢幕資料不滿會出bug;若上拉後再去下拉也會出現bug,即資料跟著手勢移動不復原 上拉載入,資料未充滿螢幕時出現bug,解決方式:在XListView中去掉onTouchEvent()方法中default下的else public boolean onTo

XrecyclerView

依賴 implementation 'com.jcodecraeer:xrecyclerview:1.2.0' 佈局 <com.jcodecraeer.xrecyclerview.XRecyclerView android:id="@+id/xrecy"

iOS開發 仿陌陌首頁效果

這幾天產品小弟說要把首頁做成像陌陌的首頁,作為一個程式設計師本來是想剁了他的,但是考慮到最近工作不好找,就忍了的。。。 陌陌首頁分析: 陌陌操作圖.gif 陌陌首頁長這樣 往上推的時候明顯感覺是下面的蓋住了上面的,所以可以分成幾個圖層,上面的在最下面的圖層,下

輪播+重新整理+資料庫

** MainActivity ** package com.example.lx_zz.activity; import android.annotation.SuppressLint; import android.support.design.widget.TabLayo

電阻

1.上拉電阻 上拉電阻的官方定義是這樣的:將不確定訊號鉗位在高電平的電阻。 OK, 不要慌,讓我們用一個簡單的例項來輔助理解。 首先,來理解一下高低電平。我們都知道在數位電路中,只有兩種狀態,要麼是高電平(一般微控制器中是5V),代表邏輯1;要麼是低電平(0V,即GND)

css修改select的箭頭的位置

修改select的樣式的基本操作如下 select { /*Chrome和Firefox裡面的邊框是不一樣的,所以複寫了一下*/ border: solid 1px #000; /*將預設的select選擇框樣式清除*/ appearance:none; -mo