android 使用 Lottie

mac2022-06-30  83

1.添加依赖

dependencies { implementation 'com.airbnb.android:lottie:2.5.5'//lottie }

2.1layout实现

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <com.airbnb.lottie.LottieAnimationView android:id="@+id/animation_view" android:layout_width="wrap_content" android:layout_height="wrap_content" app:lottie_fileName="motorcycle.json" app:lottie_autoPlay="true" app:lottie_loop="true" /> </RelativeLayout>

说明:

lottie_fileName是需要加载的动画 目录是:...\MyStudyApp\app\src\main\assets\motorycycle.json lottie_autoPlay 是否自动播放 lottie_loop是否循环播放以上两步即可现实动画效果2.2使用java代码实现 LottieAnimationView animation_view; animation_view = findViewById(R.id.animation_view); LottieComposition.Factory.fromAssetFileName(this, "happy.json", new OnCompositionLoadedListener() { @Override public void onCompositionLoaded(@Nullable LottieComposition composition) { animation_view.setComposition(composition); } });

 

3.资源 --motorcycle.json 、happy.json下载地址 --Lottie GitHub

转载于:https://www.cnblogs.com/tomarsNi/p/9431264.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)