当前位置: 代码网 > it编程>App开发>Android > Android中的HTextView库实现TextView动画效果

Android中的HTextView库实现TextView动画效果

2024年05月18日 Android 我要评论
在android开发中,我们可能会遇到实现某个textview实现动画效果。关于这种需求,我给小伙们推荐推荐htextview开源库,希望能小伙伴们提高开发效率。htextview是一个用来给text

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使用以及效果

&lt;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"/&gt;

总结

至此,我们就算是彻底了解了htextview,虽然并没有多么复杂,但是它使用的这些典型的设计模式以及各种动画的实现确实可以从中让我们学到不少知识。尤其是各种动画的具体实现,能为我们自己在做相关动画时提供不少思路!感觉给textview加动画效果还是很棒的,有机会的话可以在项目中使用到。

到此这篇关于android中的htextview库实现textview动画效果的文章就介绍到这了,更多相关android中的htextview库实现动画内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com