1.airbnb開源的lottie庫,可以加載json文件用來實現(xiàn)動畫效果,用起來也很簡單,也支持imageview顯示
使用方式:
1)添加依賴:
implementation 'com.airbnb.android:lottie:3.7.0' //lottie動畫控件
2)布局文件
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/iv_tab_msg"
app:lottie_repeatCount="0"
app:lottie_autoPlay="false"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="1.5dp"
android:src="@drawable/tab_icon_im" />
3)代碼使用
LottieAnimationView mLottieView = view.findViewById(R.id.lottie_view);
mLottieView .setAnimation(R.raw.tab_dest); //你的json文件
mLottieView .playAnimation();
//清除動畫
if (mLottieView .isAnimating()) {
mLottieView .cancelAnimation();
}
2.apng庫,支持apng圖片,但是apng圖片的后綴是以.png結(jié)尾的,需要注意。用imageview加載顯示
使用方式:
1)添加依賴
implementation 'com.github.penfeizhou.android.animation:apng:2.10.0'
2)布局文件
<ImageView
android:id="@+id/images"
android:layout_width="48dp"
android:layout_margin="6dp"
android:layout_height="48dp"
/>
3)代碼使用
ImageView imageView = view.findViewById(R.id.images);
AssetStreamLoader assetLoader = new AssetStreamLoader(requireContext(), "dialog_loading.png");
// 創(chuàng)建APNG Drawable
apngDrawable = new APNGDrawable(assetLoader); //簡單使用,有多種加載資源方式可以使用
//自動播放
imageView.setImageDrawable(apngDrawable);
apngDrawable.setAutoPlay(false);
apngDrawable.setLoopLimit(Integer.MAX_VALUE);
apngDrawable.start();
//清除動畫
apngDrawable.stop();
apngDrawable.reset();
3.pag庫,騰訊出品的支持pag圖片,圖片的后綴是以.pag結(jié)尾的,需要注意。不支持用imageview加載顯示
使用方式:
1)添加依賴
implementation 'com.tencent.tav:libpag:3.2.7.40'
2)布局文件
<org.libpag.PAGView
android:id="@+id/pagView"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="100dp" /> //需要知道具體寬高,不然有可能不顯示
3)代碼使用
PagView pagView= view.findViewById(R.id.pagView);
PAGFile pagFile = PAGFile.Load(mContext.getAssets(), "index_refresh.pag");
pagView.setComposition(pagFile);
pagView.setRepeatCount(Integer.MAX_VALUE);
pagView.play();