Android中的HTextView庫實(shí)現(xiàn)TextView動畫效果
在Android開發(fā)中,我們可能會遇到實(shí)現(xiàn)某個TextView實(shí)現(xiàn)動畫效果。關(guān)于這種需求,我給小伙們推薦推薦HTextView開源庫,希望能小伙伴們提高開發(fā)效率。HTextView是一個用來給TextView里的文字做各種轉(zhuǎn)換動畫的開源庫。
HTextView前言
第一次看到這個庫的時候就被這些動畫吸引了,不僅提供了多種動畫選擇,而且還有重復(fù)字符的位移動畫,的確別出心裁,雖然實(shí)現(xiàn)起來并不是多么復(fù)雜,但是從1700+的star數(shù)上還是可以看出它的受歡迎程度,所以今天我們就來分析看看它到底是如何實(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,雖然并沒有多么復(fù)雜,但是它使用的這些典型的設(shè)計(jì)模式以及各種動畫的實(shí)現(xiàn)確實(shí)可以從中讓我們學(xué)到不少知識。尤其是各種動畫的具體實(shí)現(xiàn),能為我們自己在做相關(guān)動畫時提供不少思路!感覺給TextView加動畫效果還是很棒的,有機(jī)會的話可以在項(xiàng)目中使用到。
到此這篇關(guān)于Android中的HTextView庫實(shí)現(xiàn)TextView動畫效果的文章就介紹到這了,更多相關(guān)Android中的HTextView庫實(shí)現(xiàn)動畫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android 組合控件實(shí)現(xiàn)布局的復(fù)用的方法
本篇文章主要介紹了Android 組合控件實(shí)現(xiàn)布局的復(fù)用的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-08-08
Android實(shí)現(xiàn)簡單的banner輪播圖
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡單的banner輪播圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-05-05
Flutter實(shí)現(xiàn)資源下載斷點(diǎn)續(xù)傳的示例代碼
在項(xiàng)目開發(fā)中,特別是C端的產(chǎn)品,資源下載實(shí)現(xiàn)斷點(diǎn)續(xù)傳是非常有必要的。今天我們不講過多原理的知識,分享下簡單實(shí)用的資源斷點(diǎn)續(xù)傳2022-07-07
Android RecyclerView添加頭部和底部的方法
這篇文章主要為大家詳細(xì)介紹了Android RecyclerView添加頭部和底部的方法,感興趣的小伙伴們可以參考一下2016-05-05
Android與H5交互產(chǎn)生Script Error踩坑解決
這篇文章主要為大家介紹了Android與H5交互產(chǎn)生Script Error問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
Android發(fā)送GET與POST請求的DEMO詳解
本篇文章是對Android發(fā)送GET與POST請求的DEMO進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06

