Android中的HTextView庫(kù)實(shí)現(xiàn)TextView動(dòng)畫效果
在Android開發(fā)中,我們可能會(huì)遇到實(shí)現(xiàn)某個(gè)TextView實(shí)現(xiàn)動(dòng)畫效果。關(guān)于這種需求,我給小伙們推薦推薦HTextView開源庫(kù),希望能小伙伴們提高開發(fā)效率。HTextView是一個(gè)用來(lái)給TextView里的文字做各種轉(zhuǎn)換動(dòng)畫的開源庫(kù)。
HTextView前言
第一次看到這個(gè)庫(kù)的時(shí)候就被這些動(dòng)畫吸引了,不僅提供了多種動(dòng)畫選擇,而且還有重復(fù)字符的位移動(dòng)畫,的確別出心裁,雖然實(shí)現(xiàn)起來(lái)并不是多么復(fù)雜,但是從1700+的star數(shù)上還是可以看出它的受歡迎程度,所以今天我們就來(lái)分析看看它到底是如何實(shí)現(xiàn)的.有哪些值得我們借鑒的地方,又有哪些不完善的地方。
HTextView的簡(jiǎn)單使用方法
HTextView的使用方法還是比較簡(jiǎn)單的,只需要調(diào)用hTextView.setAnimateType();來(lái)設(shè)定一種動(dòng)畫的類型,再調(diào)用hTextView.animateText();將字符串傳入就可以執(zhí)行切換動(dòng)畫了,此外還提供了hTextView.reset();方法來(lái)重置動(dòng)畫,具體代碼如下:
hTextView.setAnimateType(HTextViewType.SCALE); hTextView.animateText(sentences[mCounter]);
HTextView引入
寫博客的時(shí)候,最新的版本是0.1.6。小伙伴們使用的時(shí)候,可以看看有沒(méi)有更新版本。引入基礎(chǔ)模塊:
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"/>
總結(jié)
至此,我們就算是徹底了解了HTextView,雖然并沒(méi)有多么復(fù)雜,但是它使用的這些典型的設(shè)計(jì)模式以及各種動(dòng)畫的實(shí)現(xiàn)確實(shí)可以從中讓我們學(xué)到不少知識(shí)。尤其是各種動(dòng)畫的具體實(shí)現(xiàn),能為我們自己在做相關(guān)動(dòng)畫時(shí)提供不少思路!感覺(jué)給TextView加動(dòng)畫效果還是很棒的,有機(jī)會(huì)的話可以在項(xiàng)目中使用到。
到此這篇關(guān)于Android中的HTextView庫(kù)實(shí)現(xiàn)TextView動(dòng)畫效果的文章就介紹到這了,更多相關(guān)Android中的HTextView庫(kù)實(shí)現(xiàn)動(dòng)畫內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android studio編寫簡(jiǎn)單的手電筒APP
一個(gè)簡(jiǎn)單的APP控制的手電筒代碼,android studio編寫一個(gè)手電筒app,調(diào)用手機(jī)的閃光等實(shí)現(xiàn)手電筒的功能,感興趣的小伙伴們可以參考一下2016-08-08
Android自定義收音機(jī)搜臺(tái)控件RadioRulerView
這篇文章主要為大家詳細(xì)介紹了Android自定義收音機(jī)搜臺(tái)控件RadioRulerView的相關(guān)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04
Android studio listview實(shí)現(xiàn)列表數(shù)據(jù)顯示 數(shù)據(jù)循環(huán)顯示效果
這篇文章主要介紹了Android studio listview實(shí)現(xiàn)列表數(shù)據(jù)顯示 數(shù)據(jù)循環(huán)顯示功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04
Android?Studio開發(fā)實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能
這篇文章主要為大家詳細(xì)介紹了Android?Studio開發(fā)實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
Android 開發(fā)延時(shí)調(diào)用的幾種方法
本篇文章主要介紹Android 延遲, 在Android 程序開發(fā)過(guò)程中經(jīng)常會(huì)遇到程序推遲時(shí)間執(zhí)行,這里整理了幾種方法,以便Android 開發(fā)的朋友參考2016-07-07
Android編程基于距離傳感器控制手機(jī)屏幕熄滅的方法詳解
這篇文章主要介紹了Android編程基于距離傳感器控制手機(jī)屏幕熄滅的方法,結(jié)合具體實(shí)例形式分析了Android距離傳感器的控制屏幕熄滅的實(shí)現(xiàn)方法與相關(guān)操作技巧,需要的朋友可以參考下2017-11-11
Android應(yīng)用開發(fā)中Fragment存儲(chǔ)功能的基本用法
這篇文章主要介紹了Android應(yīng)用開發(fā)中使用Fragment存儲(chǔ)功能的基本用法,包括對(duì)Fragment的非中斷保存setRetaineInstance的講解,需要的朋友可以參考下2016-02-02
Android Zygote啟動(dòng)構(gòu)造流程及進(jìn)程創(chuàng)建詳解
這篇文章主要為大家介紹了Android Zygote啟動(dòng)構(gòu)造流程及進(jìn)程創(chuàng)建詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07
Android實(shí)現(xiàn)電子羅盤(指南針)方向傳感器的應(yīng)用
今天小編就為大家分享一篇關(guān)于Android實(shí)現(xiàn)電子羅盤(指南針)方向傳感器的應(yīng)用,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-03-03

