Android支持动画效果的库

1.airbnb开源的lottie库,可以加载json文件用来实现动画效果,用起来也很简单,也支持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结尾的,需要注意。用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");
                // 创建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结尾的,需要注意。不支持用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();
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容