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

相关文章

Spring如何使用注解@DependsOn控制Bean加载顺序

《Spring如何使用注解@DependsOn控制Bean加载顺序》:本文主要介绍Spring如何使用注解@DependsOn控制Bean加载顺序,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录1.javascript 前言2. 代码实现总结1. 前言默认情况下,Spring加载Bean的顺

SQL Server修改数据库名及物理数据文件名操作步骤

《SQLServer修改数据库名及物理数据文件名操作步骤》在SQLServer中重命名数据库是一个常见的操作,但需要确保用户具有足够的权限来执行此操作,:本文主要介绍SQLServer修改数据... 目录一、背景介绍二、操作步骤2.1 设置为单用户模式(断开连接)2.2 修改数据库名称2.3 查找逻辑文件名

Oracle修改端口号之后无法启动的解决方案

《Oracle修改端口号之后无法启动的解决方案》Oracle数据库更改端口后出现监听器无法启动的问题确实较为常见,但并非必然发生,这一问题通常源于​​配置错误或环境冲突​​,而非端口修改本身,以下是系... 目录一、问题根源分析​​​二、保姆级解决方案​​​​步骤1:修正监听器配置文件 (listener.

springboot加载不到nacos配置中心的配置问题处理

《springboot加载不到nacos配置中心的配置问题处理》:本文主要介绍springboot加载不到nacos配置中心的配置问题处理,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录springboot加载不到nacos配置中心的配置两种可能Spring Boot 版本Nacos

Linux中修改Apache HTTP Server(httpd)默认端口的完整指南

《Linux中修改ApacheHTTPServer(httpd)默认端口的完整指南》ApacheHTTPServer(简称httpd)是Linux系统中最常用的Web服务器之一,本文将详细介绍如何... 目录一、修改 httpd 默认端口的步骤1. 查找 httpd 配置文件路径2. 编辑配置文件3. 保存

使用Python获取JS加载的数据的多种实现方法

《使用Python获取JS加载的数据的多种实现方法》在当今的互联网时代,网页数据的动态加载已经成为一种常见的技术手段,许多现代网站通过JavaScript(JS)动态加载内容,这使得传统的静态网页爬取... 目录引言一、动态 网页与js加载数据的原理二、python爬取JS加载数据的方法(一)分析网络请求1

Kotlin Compose Button 实现长按监听并实现动画效果(完整代码)

《KotlinComposeButton实现长按监听并实现动画效果(完整代码)》想要实现长按按钮开始录音,松开发送的功能,因此为了实现这些功能就需要自己写一个Button来解决问题,下面小编给大... 目录Button 实现原理1. Surface 的作用(关键)2. InteractionSource3.

IDEA下"File is read-only"可能原因分析及"找不到或无法加载主类"的问题

《IDEA下Fileisread-only可能原因分析及找不到或无法加载主类的问题》:本文主要介绍IDEA下Fileisread-only可能原因分析及找不到或无法加载主类的问题,具有很好的参... 目录1.File is read-only”可能原因2.“找不到或无法加载主类”问题的解决总结1.File

Nginx 413修改上传文件大小限制的方法详解

《Nginx413修改上传文件大小限制的方法详解》在使用Nginx作为Web服务器时,有时会遇到客户端尝试上传大文件时返回​​413RequestEntityTooLarge​​... 目录1. 理解 ​​413 Request Entity Too Large​​ 错误2. 修改 Nginx 配置2.1

Python对PDF书签进行添加,修改提取和删除操作

《Python对PDF书签进行添加,修改提取和删除操作》PDF书签是PDF文件中的导航工具,通常包含一个标题和一个跳转位置,本教程将详细介绍如何使用Python对PDF文件中的书签进行操作... 目录简介使用工具python 向 PDF 添加书签添加书签添加嵌套书签Python 修改 PDF 书签Pytho