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

