Android 第三方庫lottie、mmkv的使用詳解
Android端使用方法
首先,需要在當前項目的build.gradle下添加依賴代碼:
implementation 'com.airbnb.android:lottie:2.8.0'
其次,Lottie默認讀取Assets中的文件,我們需要把設(shè)計導出的動畫文件.json 保存在app/src/main/assets文件里。若沒有assets文件,則新建一個如下圖:
在assets添加images文件夾,并將json中需要用的的圖片放入其中,注意,圖片名要于json中保持一直。
最后,在布局xml中,添加即可:
<com.airbnb.lottie.LottieAnimationView android:id="@+id/lottie_layer_name" android:layout_width="wrap_content" android:layout_height="wrap_content" app:lottie_autoPlay="true" app:lottie_fileName="immersive_feeling_create_gradients.json" app:lottie_imageAssetsFolder="images" app:lottie_loop="true" />
lottie_fileName:表示本地Assets文件中存的json動畫文件
lottie_loop:表示動畫循環(huán)執(zhí)行
lottie_autoPlay:表示自動播放動畫
lottie_imageAssetsFolder:表示支持動畫的圖片所在文件夾
常用方法:
animationView.isAnimating():動畫是否在播放;
animationView.playAnimation():播放動畫;
animationView.pauseAnimation():暫停動畫;
animationView.cancelAnimation():取消動畫;
animationView.setProgress(progress):設(shè)置進度,progress范圍0~1;
animationView.setMinAndMaxProgress(min,max):設(shè)置播放范圍,0~1。
mmkv
mmkv是基于 mmap 的高性能通用 key-value 組件,由微信團隊開發(fā)的。其類似于小型數(shù)據(jù)庫,可以存儲一些信息。其使用非常簡單,無需任何配置,所有變更立馬生效。
首先,需要在當前項目的build.gradle下添加依賴代碼:
implementation 'com.tencent:mmkv-static:1.0.23'
其次,聲明與實例mmkv
MMKV.initialize(this); MMKV kv = MMKV.defaultMMKV();
隨后,存儲信息
kv.encode("bool", true); kv.encode("int", 1); kv.encode("string", "Hello world!");
最后,取出信息
boolean bValue = kv.decodeBool("bool"); int iValue = kv.decodeInt("int"); String str = kv.decodeString("string");
到此這篇關(guān)于Android 三方庫lottie、mmkv的使用詳解的文章就介紹到這了,更多相關(guān)Android 三方庫lottie mmkv使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android?14新功能HighLights快速實現(xiàn)文本高亮
這篇文章主要為大家介紹了Android?14新功能HighLights快速實現(xiàn)文本高亮示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-03-03ViewModel中StateFlow和SharedFlow單元測試使用詳解
這篇文章主要為大家介紹了ViewModel中StateFlow和SharedFlow單元測試使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-01-01Android實現(xiàn)創(chuàng)意LoadingView動畫效果
這篇文章主要介紹了Android實現(xiàn)創(chuàng)意LoadingView動畫效果的相關(guān)資料,需要的朋友可以參考下2016-02-02Android實現(xiàn)簡潔的APP更新dialog數(shù)字進度條
這篇文章主要為大家詳細介紹了Android實現(xiàn)簡潔的APP更新dialog數(shù)字進度條,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04