1.RecyclerViewLoopScrollAnimation项目介绍

RecyclerViewLoopScrollAnimation 适用于Android RecyclerView的循环滚动动画的帮助类,可实现类似于老虎机抽奖,数字滚动等效果。

2. 效果展示

git太大,压缩的厉害,导致帧率太低,建议下载工程运行查看实际效果。

3. 使用方法:

第一步: 在你的根目录中的 build.gradle 文件中,repositories 标签下添加jitpack maven仓库:

Add it in your root build.gradle at the end of repositories:

allprojects {repositories {...maven { url 'https://jitpack.io' }}
}

若使用Gradle 7.0 ,则在setting.gradle中的dependencyResolutionManagement的repositories标签中添加:

dependencyResolutionManagement {repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories {...maven { url 'https://jitpack.io' }...}
}
...

第二步: 添加依赖

Add the dependency

dependencies {implementation 'com.github.xiangang:RecyclerViewLoopScrollAnimation:v1.0.0-alpha01'
}

4. 使用示例

使用示例如下:

//创建一个RecyclerViewLoopScrollAnimation实例
val recyclerViewLoopScrollAnimation = RecyclerViewLoopScrollAnimation()
//创建一个Configuration
val recyclerViewLoopScrollAnimationConfiguration = RecyclerViewLoopScrollAnimation.build {scrollAnimatorDuration = 4000L}
//设置Configuration
recyclerViewLoopScrollAnimation.setConfiguration(recyclerViewLoopScrollAnimationConfiguration)
//将recyclerViewLoopScrollAnimation关联到RecyclerView
recyclerViewLoopScrollAnimation.attachToRecyclerView(holder.recyclerView)
//配合LooperLinearLayoutManager实现无限滚动
val looperLinearLayoutManager = LooperLinearLayoutManager(context, RecyclerView.VERTICAL, false)
recyclerView.layoutManager = looperLinearLayoutManager
//设置滚动Action,用于滚动时返回当前显示View的Position
recyclerViewLoopScrollAnimation.setRecyclerViewScrollAction(object:RecyclerViewScrollAction {override fun findFirstVisibleItemPosition(): Int {return looperLinearLayoutManager.findFirstVisibleItemPosition()}override fun findLastVisibleItemPosition(): Int {return looperLinearLayoutManager.findLastVisibleItemPosition()}
})
//开始动画
recyclerViewLoopScrollAnimation.start()

更多用法可参考工程里的app。

5. 其它

RecyclerViewLoopScrollAnimation.Configuration配置类:

/**
* 配置
*/
class Configuration {/*** 是否禁止Item相应手指滑动*/var disableItemTouchListener = true/*** 第一阶段的滚动动画时长*/var scrollAnimatorDuration = 3000L/*** 第一阶段的滚动动画的插值器*/var scrollAnimatorInterpolator = AccelerateDecelerateInterpolator()/*** 是否开启弹簧动画*/var enableSpringAnimator = true/*** 第一阶段的滚动动画针对item的滚动步长(scrollBy方法的y参数)*/var scrollAnimatorScrollByYStep = 30/*** 第二阶段的弹簧动画的SpringForce*/var springAnimatorForce: SpringForce = SpringForce(0f).setDampingRatio(SpringForce.DAMPING_RATIO_HIGH_BOUNCY).setStiffness(SpringForce.STIFFNESS_VERY_LOW).setDampingRatio(0.2f).setStiffness(350f)/*** 弹簧动画的起始位置*/var springAnimatorStartValue = -50f}

RecyclerViewLoopScrollAnimation.build的用法为Function literals with receiver:

/**
* 配置
*/
//创建一个RecyclerViewLoopScrollAnimation实例
val recyclerViewLoopScrollAnimation = RecyclerViewLoopScrollAnimation()
//创建一个Configuration
val recyclerViewLoopScrollAnimationConfiguration = RecyclerViewLoopScrollAnimation.build {scrollAnimatorDuration = 4000L}
//设置Configuration
recyclerViewLoopScrollAnimation.setConfiguration(recyclerViewLoopScrollAnimationConfiguration)

扩展阅读:你会用Kotlin实现构建者模式吗?

其它接口:

/**
* RecyclerView滚动过程中需要执行的Action
*/
fun setRecyclerViewScrollAction(recyclerViewScrollAction: RecyclerViewScrollAction) {this.recyclerViewScrollAction = recyclerViewScrollAction
}/**
* 设置滚动动画监听器
*/
fun setOnSpringAnimationEndListener(onScrollAnimatorListener: Animator.AnimatorListener) {this.onScrollAnimatorListener = onScrollAnimatorListener
}/**
* 设置弹簧动画结束监听器
* 可用于动画结束后执行爆炸粒子效果
*/
fun setOnSpringAnimationEndListener(onAnimationEndListener: DynamicAnimation.OnAnimationEndListener) {this.onSpringAnimationEndListener = onAnimationEndListener
}

License

Copyright 2022 xiangangLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Android RecyclerView实现类似于老虎机抽奖,数字滚动等动画效果相关推荐

  1. Swift 动画 —— 数字滚动UILabel动画

    新建一个Swift工程.要做到数字滚动的动画,可能很多人都会想到用UIView的animate方法,但是UIView的animate方法只会做关于UIView的Frame,alpha,color,tr ...

  2. android app启动图片 加动画效果,Android Studio开发APP启动程序时开屏简单动画效果快速有效解决方案...

    Android Studio开发APP启动程序时开屏简单动画效果快速有效解决方案 大家在设计APP的末期,都会想给APP搞一些"花里胡哨"的特效来提高APP的B格.博主表示亲测有效 ...

  3. matlab车轮滚动动画,flash制作车轮往前滚动的动画效果

    用flash制作一种就好像车轮在往前转动方法,操作很简单,适合新手来学习,推荐过来,一起来学习吧! 步骤: 1.打开软件,,打开flash文档然后点击图层一第一帧.再点击颜料版把填充色改成没有,然后按 ...

  4. 【web前端】JavaScript实现图片幻灯片滚动播放动画效果

    JavaScript实现图片幻灯片滚动播放动画效果 by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.co ...

  5. html数字动画效果,原生JavaScript代码实现数字更新的动画效果

    前言 在很多数据统计类型网站的首页,经常会看到数据在动态的更新,而且会以动画的效果呈现. 今天这篇文章我们就来看看这个效果如何实现吧. 文中的代码已经放到github上了,感兴趣的同学可以自取.htt ...

  6. vue数字递增的动画效果

    安装 npm install vue-count-to -S 使用 //vue-countTo---简单好用的一个数字滚动插件 //在js里面引入并且挂载到组件 import CountTo from ...

  7. 属性动画-仿网易彩票数字奖池动画效果

    一.先看网易中奖奖池的效果 二.思路 明显的动画效果,而且是随着时间的推移,前面的数字暂停下来.数字的滚动用线程?!当然可以实现.但是前面的数字停下,这种效果不好处理.我开始想的是从最大的数字开始跑, ...

  8. Android自定义View——仿ViVO X6 极速闪充动画效果

    一直都在看自定义View,经过一个星期的坚持,基本上能够写出一些比较实用的控件效果了,今天天气太热,就待在家里玩手机,然后手机没电了,在充电的时候,看到了手机的充电动画,觉得挺酷,然后自己我就仔细的分 ...

  9. UICountingLabel实现数字变化的动画效果-b

    在大多数金融类 app 上或者其他 app 需要数字展示的地方, 经常会有如下的动画效果: 动画效果 怎么做呢? 一.下载UICountingLabel 下载地址: https://github.co ...

最新文章

  1. php 前端控制器,前端控制器模式
  2. c++对象长度之空类(1)
  3. 遍历同辈节电的方法_jQuery遍历
  4. marquee文字起始位置_PS修图改字无痕扫描件复印件截图文字英文日期修改:制作漂亮红色丝绸文字图片的PS教程...
  5. Do you have an English name? 你有英文名吗?
  6. python 计算协方差矩阵_opencv2学习:计算协方差矩阵
  7. python删除mysql数据库_python 删除mysql数据库
  8. 基于并行附加特征提取网络的SSD地面小目标检测模型
  9. [USACO08DEC]拍头Patting Heads 数学 BZOJ 1607
  10. Centos如何使用SSH远程连接主机
  11. oracle发邮件没有反应,[数据库]Oracle发邮件,权限问题
  12. Spring中使用集成MongoDB Client启动时报错:rc: 48
  13. [Java] 蓝桥杯 BEGIN-1 入门训练 A+B问题
  14. Andriod UI设计之度量单位说明(DIP,DP,PX,SP)
  15. SP2010开发和VS2010专家食谱--第七章节--使用客户端对象模型
  16. Java生成32位全局唯一id
  17. php ziparchive类,PHP Zip ZipArchive 类_编程学问网
  18. 程序员工资多高才算高?
  19. 游戏设计---游戏中战斗力计算方法(整理)
  20. 高斯拉普拉斯——图像金字塔

热门文章

  1. 《老鹰抓小鸡》将代表中国动画电影走出国门,走向世界,yyds❤
  2. Apple Watch更懂女人心
  3. 桌面上打开计算机有延迟感觉,电脑中右击操作反应慢如何解决|解决右键菜单弹出延迟的方法...
  4. 面试官硬核提问,教你轻松应对(面试小技巧)1
  5. 微信小程序之三元操作符
  6. linux mint回收站,Autotrash:定时自动删除旧垃圾的命令行工具
  7. 未来机器人生活的畅享之旅
  8. html学习 - jquery事件监听详解
  9. 微信浏览器网页点击图片缩放
  10. linux 批量下载fnl,TMS370C356FNL