Android中的HTextView库实现TextView动画效果
(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun)
在Android
开发中,我们可能会遇到实现某个TextView
实现动画效果。关于这种需求,我给小伙们推荐推荐HTextView
开源库,希望能小伙伴们提高开发效率。HTextView是一个用来给TextView里的文字做各种转换动画的开源库。
HTextView前言
第一次看到这个库的时候就被这些动画吸引了,不仅提供了多种动画选择,而且还有重复字符的位移动画,的确别出心裁,虽然实现起来并不是多么复杂,但是从1700+的star数上还是可以看出它的受欢迎程度,所以今天我们就来分析看看它到底是如何实现的.有哪些值得我们借鉴的地方,又有哪些不完善的地方。
HTextView的简单使用方法
HTextView的使用方法还是比较简单的,只需要调用hTextView.setAnimateType();
来设定一种动画的类型,再调用hTextView.animateText();
将字符串传入就可以执行切换动画了,此外还提供了hTextView.reset();
方法来重置动画,具体代码如下:
hTextView.setAnimateType(HTextViewType.SCALE); hTextView.animateText(sentences[mCounter]);
HTextView引入
写博客的时候,最新的版本是0.1.6
。小伙伴们使用的时候,可以看看有没有更新版本。引入基础模块:
implementation "com.hanks:htextview-base:0.1.6"
下面的可以按需引入:
implementation "com.hanks:htextview-fade:0.1.6" implementation "com.hanks:htextview-line:0.1.6" implementation "com.hanks:htextview-rainbow:0.1.6" implementation "com.hanks:htextview-typer:0.1.6" implementation "com.hanks:htextview-scale:0.1.6" implementation "com.hanks:htextview-evaporate:0.1.6" implementation "com.hanks:htextview-fall:0.1.6"
line使用以及效果
<com.hanks.htextview.line.LineTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right" android:paddingRight="10dp" android:text="This is LineTextView\nToday is Monday" android:textSize="16sp" app:animationDuration="3000" app:lineColor="#1367bc" app:lineWidth="4dp"/>
fade使用以及效果
<com.hanks.htextview.fade.FadeTextView android:layout_width="240dp" android:layout_height="150dp" android:gravity="left" android:letterSpacing="0.08" android:lineSpacingMultiplier="1.3" android:text="This is FadeTextView" android:textColor="#fff" android:textSize="20sp" app:animationDuration="1500"/>
typer使用以及效果
<com.hanks.htextview.typer.TyperTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="this is init sentence." app:charIncrease="3" app:typerSpeed="80"/>
rainbow使用以及效果
<com.hanks.htextview.rainbow.RainbowTextView android:layout_width="120dp" android:layout_height="wrap_content" android:gravity="right" android:text="this is init sentence" android:textSize="20sp" app:colorSpace="150dp" app:colorSpeed="4dp"/>
scale使用以及效果
<com.hanks.htextview.scale.ScaleTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="this is init sentence" android:textSize="16sp"/>
evaporate使用以及效果
<com.hanks.htextview.evaporate.EvaporateTextView android:layout_width="match_parent" android:layout_height="100dp" android:gravity="center" android:paddingTop="8dp" android:text="this is init sentence" android:textSize="20sp"/>
fall使用以及效果
<com.hanks.htextview.fall.FallTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="20dp" android:text="this is init sentence" android:textSize="16sp"/>
总结
至此,我们就算是彻底了解了HTextView,虽然并没有多么复杂,但是它使用的这些典型的设计模式以及各种动画的实现确实可以从中让我们学到不少知识。尤其是各种动画的具体实现,能为我们自己在做相关动画时提供不少思路!感觉给TextView
加动画效果还是很棒的,有机会的话可以在项目中使用到。
到此这篇关于Android中的HTextView库实现TextView动画效果的文章就介绍到这了,更多相关Android中的HTextView库实现动画内容请搜索程序员之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持程序员之家!
相关文章
Flutter悬浮按钮FloatingActionButton使用详解
本文主要介绍了Flutter悬浮按钮FloatingActionButton使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2021-07-07Android ContentProvider获取手机联系人实例
这篇文章主要介绍了Android ContentProvider获取手机联系人实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-02-02Flutter音乐播放插件audioplayers使用步骤详解
audioplayers是一个可以支持同时播放多个音频文件的Flutter的插件,可以播放多个同时的音频文件,这篇文章主要介绍了audioplayers的使用步骤,感兴趣想要详细了解可以参考下文2023-05-05Android仿微信清理内存图表动画(解决surfaceView屏幕闪烁问题)demo实例详解
本文通过实例代码给大家讲解android仿微信清理内存图表动画(解决surfaceView屏幕闪烁问题)的相关资料,本文介绍的非常详细,具有参考借鉴价值,需要的朋友可以参考下2016-09-09Android从0到完整项目(1)使用Android studio 创建项目详解
本篇文章主要介绍了Android从0到完整项目(1)使用Android studio 创建项目详解,具有一定的参考价值,有兴趣的可以了解一下2017-07-07Android实现微信自动向附近的人打招呼(AccessibilityService)
这篇文章主要为大家详细介绍了实现微信自动向附近的人打招呼,实现收到指定账户推送文章时自动进入微信打开链接,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2016-12-12
最新评论