1.添加依賴java
dependencies { implementation 'com.airbnb.android:lottie:2.5.5'//lottie }
2.1layout實現android
<?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>
說明:git
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