Android 使乐蒂动画仅在播放时可见
为了实现标题中所述的目标,我有两个独立的问题 第一个问题是:默认情况下,XML中Android 使乐蒂动画仅在播放时可见,android,lottie,Android,Lottie,为了实现标题中所述的目标,我有两个独立的问题 第一个问题是:默认情况下,XML中com.airbnb.lottie.LottieAnimationView的可见性状态是什么?我在XML中使用了两种不同的LottieAnimationView,它们具有相同的特征: <com.airbnb.lottie.LottieAnimationView android:id="@+id/lottie_animation_ribbon_and_confetti" a
com.airbnb.lottie.LottieAnimationView
的可见性状态是什么?我在XML中使用了两种不同的LottieAnimationView,它们具有相同的特征:
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottie_animation_ribbon_and_confetti"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:lottie_autoPlay="false"
app:lottie_fileName="exploding-ribbon-and-confetti.json"
app:lottie_loop="true"
app:lottie_repeatCount="1"/>
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottie_cat_throws_cup"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/puntuacionTotal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/puntosAtrevimiento"
app:layout_constraintBottom_toTopOf="@id/textoAtrevimiento"
app:lottie_autoPlay="false"
app:lottie_fileName="cat_throws_cup.json"
app:lottie_loop="true"
app:lottie_repeatCount="1"
/>
另一次尝试:
lottieCatThrowsCup.setVisibility(View.VISIBLE);
lottieCatThrowsCup.playAnimation();
if(!lottieCatThrowsCup.isAnimating())lottieCatThrowsCup.cancelAnimation();
第三次尝试:
lottieCatThrowsCup.setVisibility(View.VISIBLE);
lottieCatThrowsCup.playAnimation();
lottieCatThrowsCup.cancelAnimation();
第四次尝试:
lottieCatThrowsCup.setVisibility(View.VISIBLE);
lottieCatThrowsCup.playAnimation();
lottieCatThrowsCup.addAnimatorListener(this);
@Override
public void onAnimationEnd(Animator animation) {
animation.setVisibility(View.GONE);
}
在我看来,最简单的解决方案是在
com.airbnb.lottie.lottie animationview
上使用一个xml属性来指示它在默认情况下不必可见,除非它被播放,但它似乎不存在。。。你们怎么解决这个问题?提前感谢。还有其他侦听器
可用于隐藏/显示乐天视图
mAddedToCartAnimation.addAnimatorListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
Log.e("Animation:","start");
lottieCatThrowsCup.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animator animation) {
Log.e("Animation:","end");
lottieCatThrowsCup.setVisibility(View.GONE);
}
@Override
public void onAnimationCancel(Animator animation) {
Log.e("Animation:","cancel");
}
@Override
public void onAnimationRepeat(Animator animation) {
Log.e("Animation:","repeat");
}
});
使用以下命令:
lottieCatThrowsCup.setVisibility(View.VISIBLE);
lottieCatThrowsCup.playAnimation();
lottieCatThrowsCup.addAnimatorListener(this);
@Override
public void onAnimationEnd(Animator animation) {
lottieCatThrowsCup.setVisibility(View.GONE);
}
将
Animator.AnimatorListener
添加到您的LottieAnimationView
中,并在onAnimationStart()和onAnimationEnd()中处理其可见性
lottieAnimationView.addAnimatorListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
// Make the LottieAnimationView visible here
}
@Override
public void onAnimationEnd(Animator animator) {
// Hide the LottieAnimationView here
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
你好,朋友,这个有用。不过我还有一个问题。我在同一个活动上有很多动画,你知道有没有办法在onAnimationStart和onAnimationEnd中使用通用动画对象而不是lottieCatThrowsCup,这样,根据单击的动画,onAnimationStart将显示类似于animation.setVisibility(View.VISIBLE)的内容?(当然之前我会在所有动画中使用.addAnimationListener(此选项))您的解决方案的问题是,如果我有许多动画需要在onAnimationStart中设置为可见,我不希望在只播放一个动画时所有动画都可见。@assensi为所有
乐蒂动画使用一个对象可能会产生问题。每个动画将具有不同的时间长度。在这种情况下,单个对象不起作用。对于屏幕上的每个Lottie视图
,你需要有不同的监听器。谢谢,伙计,这很管用。
lottieAnimationView.addAnimatorListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
// Make the LottieAnimationView visible here
}
@Override
public void onAnimationEnd(Animator animator) {
// Hide the LottieAnimationView here
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});