添加依赖compile 'com.airbnb.android:lottie:2.2.0'
进入下载Demo
将项目中的示例中的assets文件夹拷贝到自己新建的项目
https://github.com/airbnb/lottie-android
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" 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/lav_show" android:layout_width="wrap_content" android:layout_height="wrap_content" app:lottie_fileName="Hello World.json" app:lottie_loop="true" app:lottie_autoPlay="true" /> </RelativeLayout>
public class MainActivity extends AppCompatActivity {
private LottieAnimationView lav_show;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lav_show = (LottieAnimationView) findViewById(R.id.lav_show);
LottieComposition.Factory.fromAssetFileName(this, "City.json",
new OnCompositionLoadedListener() {
@Override public void onCompositionLoaded(@Nullable LottieComposition composition) {
lav_show.setComposition(composition);
}
});
}
}