Android支持動畫效果的庫

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();
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容