1.添加依赖
dependencies {
implementation 'com.airbnb.android:lottie:2.5.5'//lottie
}
2.1layout实现
<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" />
说明:
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下载地址
手机扫一扫
移动阅读更方便
你可能感兴趣的文章