📅  最后修改于: 2023-12-03 14:39:08.104000             🧑  作者: Mango
In Android development, Lottie is a powerful library that allows you to easily add animations to your application. One common requirement is to auto hide an animation at the end without any manual intervention. In this tutorial, we will explore how to achieve this using Lottie in Android.
dependencies {
implementation 'com.airbnb.android:lottie:3.7.0'
}
Add Lottie animation file - Obtain or create a Lottie animation file in JSON format. You can find pre-built animations from websites like LottieFiles or create custom ones using Adobe After Effects and exporting as JSON.
Create a LottieAnimationView - In your activity layout XML file, add a LottieAnimationView that will display your animation.
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:lottie_fileName="your_animation.json"
app:lottie_autoPlay="true"
app:lottie_loop="false" />
LottieAnimationView animationView = findViewById(R.id.animation_view);
animationView.addAnimatorListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
// Animation started
}
@Override
public void onAnimationEnd(Animator animation) {
// Animation ended, hide the view here
animationView.setVisibility(View.GONE);
}
@Override
public void onAnimationCancel(Animator animation) {
// Animation cancelled
}
@Override
public void onAnimationRepeat(Animator animation) {
// Animation repeated
}
});
GONE
.By following the above steps, you can easily achieve an auto-hide feature for Lottie animations in your Android application. Lottie provides a seamless way to integrate captivating animations into your app while allowing control over their lifecycle. Happy animating with Lottie!