PullToRefresh修改上拉下拉加载动画

2024-09-01 11:32

本文主要是介绍PullToRefresh修改上拉下拉加载动画,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

修改PullTuRefreshListView源码:
实现 动画加载:

第一步:

源码分析:

PullToRefrehListView 默认加载动画是很难看的:
这里写图片描述

默认是很难看的 但我们想要实现我们的效果怎么办?

分析源码:

找到PullRefreshListView 分析:

我们知道 上拉和下拉加载 动画无非是 pullToRefreshListView 中添加了头和脚, 而头和脚都是动画!!

PullToRefreshListView.java 两个动画类变量:

//定义  头部和尾部的加载动画private LoadingLayout mHeaderLoadingView;private LoadingLayout mFooterLoadingView;...//加载布局@Overrideprotected 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 nowmHeaderLayout = 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:zhao_hero@163.com* 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();}@Overrideprotected int getDefaultDrawableResId() {//返回   自定义动画布局return R.drawable.ptr_animation;}@Overrideprotected void onLoadingDrawableSet(Drawable imageDrawable) {}@Overrideprotected void onPullImpl(float scaleOfLayout) {}@Overrideprotected void pullToRefreshImpl() {}//刷新的时候@Overrideprotected void refreshingImpl() {mAnimationDrawable.start();//开启动画}@Overrideprotected void releaseToRefreshImpl() {}@Overrideprotected 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>

这就完成了自定义下拉和上拉动画,修改部分源码以及自定义帧动画类,效果图:这里写图片描述

源码:
https://github.com/zqHero/PullToRefreshDemo

参考博客:

http://blog.csdn.net/plmmmmlq/article/details/50068717

这篇关于PullToRefresh修改上拉下拉加载动画的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1126810

相关文章

使用animation.css库快速实现CSS3旋转动画效果

《使用animation.css库快速实现CSS3旋转动画效果》随着Web技术的不断发展,动画效果已经成为了网页设计中不可或缺的一部分,本文将深入探讨animation.css的工作原理,如何使用以及... 目录1. css3动画技术简介2. animation.css库介绍2.1 animation.cs

重新对Java的类加载器的学习方式

《重新对Java的类加载器的学习方式》:本文主要介绍重新对Java的类加载器的学习方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、介绍1.1、简介1.2、符号引用和直接引用1、符号引用2、直接引用3、符号转直接的过程2、加载流程3、类加载的分类3.1、显示

在 PyQt 加载 UI 三种常见方法

《在PyQt加载UI三种常见方法》在PyQt中,加载UI文件通常指的是使用QtDesigner设计的.ui文件,并将其转换为Python代码,以便在PyQt应用程序中使用,这篇文章给大家介绍在... 目录方法一:使用 uic 模块动态加载 (不推荐用于大型项目)方法二:将 UI 文件编译为 python 模

Spring框架中@Lazy延迟加载原理和使用详解

《Spring框架中@Lazy延迟加载原理和使用详解》:本文主要介绍Spring框架中@Lazy延迟加载原理和使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、@Lazy延迟加载原理1.延迟加载原理1.1 @Lazy三种配置方法1.2 @Component

SpringBoot中配置文件的加载顺序解读

《SpringBoot中配置文件的加载顺序解读》:本文主要介绍SpringBoot中配置文件的加载顺序,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot配置文件的加载顺序1、命令⾏参数2、Java系统属性3、操作系统环境变量5、项目【外部】的ap

Docker镜像修改hosts及dockerfile修改hosts文件的实现方式

《Docker镜像修改hosts及dockerfile修改hosts文件的实现方式》:本文主要介绍Docker镜像修改hosts及dockerfile修改hosts文件的实现方式,具有很好的参考价... 目录docker镜像修改hosts及dockerfile修改hosts文件准备 dockerfile 文

Spring Boot 配置文件之类型、加载顺序与最佳实践记录

《SpringBoot配置文件之类型、加载顺序与最佳实践记录》SpringBoot的配置文件是灵活且强大的工具,通过合理的配置管理,可以让应用开发和部署更加高效,无论是简单的属性配置,还是复杂... 目录Spring Boot 配置文件详解一、Spring Boot 配置文件类型1.1 applicatio

Python实现无痛修改第三方库源码的方法详解

《Python实现无痛修改第三方库源码的方法详解》很多时候,我们下载的第三方库是不会有需求不满足的情况,但也有极少的情况,第三方库没有兼顾到需求,本文将介绍几个修改源码的操作,大家可以根据需求进行选择... 目录需求不符合模拟示例 1. 修改源文件2. 继承修改3. 猴子补丁4. 追踪局部变量需求不符合很

SpringBoot项目启动报错"找不到或无法加载主类"的解决方法

《SpringBoot项目启动报错找不到或无法加载主类的解决方法》在使用IntelliJIDEA开发基于SpringBoot框架的Java程序时,可能会出现找不到或无法加载主类com.example.... 目录一、问题描述二、排查过程三、解决方案一、问题描述在使用 IntelliJ IDEA 开发基于

Linux修改pip和conda缓存路径的几种方法

《Linux修改pip和conda缓存路径的几种方法》在Python生态中,pip和conda是两种常见的软件包管理工具,它们在安装、更新和卸载软件包时都会使用缓存来提高效率,适当地修改它们的缓存路径... 目录一、pip 和 conda 的缓存机制1. pip 的缓存机制默认缓存路径2. conda 的缓