Hi
I'm using Lottie inside recyclerView.I put my json files inside asset folder.My goal is to play animation and when it finished then start activity.Here is a my source
`if (story.isRead)
lottieAnimationView.setAnimation("story_archive_gray.json");
else
lottieAnimationView.setAnimation("story_archive_blue.json");
rootView.setOnClickListener(view -> {
lottieAnimationView.addAnimatorListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
SPLogger.logMassage("animationListener","onAnimationEnd");
animation.cancel();
//call activity
}
@Override
public void onAnimationCancel(Animator animation) {
SPLogger.logMassage("animationListener","onAnimationCancel");
}
@Override
public void onAnimationRepeat(Animator animation) {
SPLogger.logMassage("animationListener","onAnimationRepeat");
}
});
lottieAnimationView.playAnimation();
});`
My problem is, sometimes can't play animation successfully and onAnimationCancel called automatically .do you have any suggestion about my problem ?
Thanks.
Best regards
@Bekakk Where are you setting that from, onCreatetViewHolder or onBindViewHolder?
@Bekakk Does it happen when you scroll, and what do you mean by "sometimes"? How frequently, does it seems correlated with anything else?
If you could attach a sample project, that would be great.
maybe you can set lottieanimation file in xml,like this app:lottie_fileName="lottie/talentshow_give_like.json"
I also encountered this , ` override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val moment = momentList[position]
holder.videoView.prepare(moment.videoUrl)
if (moment.isOwner()) {
holder.deleteImageView.visibility = View.VISIBLE
} else {
holder.deleteImageView.visibility = View.INVISIBLE
}
holder.deleteImageView.setOnClickListener {
deleteCallback?.invoke(holder.adapterPosition, moment)
}
holder.shareView.setOnClickListener {
shareCallback?.invoke(moment)
}
holder.videoView.retryCallback = {
holder.videoView.play(moment, holder.adapterPosition, true)
}
setupLikesData(holder, moment, position)
}
override fun onViewDetachedFromWindow(holder: MyViewHolder) {
holder.videoView.stop()
}
private fun setupLikesData(
holder: MyViewHolder,
moment: Moment,
position: Int
) {
holder.giveLikesAnimationView.setAnimation("lottie/talentshow_give_like.json")
holder.giveLikesAnimationView.speed = 0f
if (moment.isLiked()) {
holder.giveLikesAnimationView.progress = 1f
} else {
holder.giveLikesAnimationView.progress = 0f
}
holder.likesTextView.text = moment.likes.processLikesCount()
holder.likesTextView.typeface = typeFace
holder.giveLikesAnimationView.setOnClickListener {
if (!moment.isLiked()) {
holder.giveLikesAnimationView.speed = 1f
holder.giveLikesAnimationView.playAnimation()
likeCallback?.invoke(position, moment)
} else {
likeCallback?.invoke(position, moment)
}
}
}`,when i scoll the recyclerview,the animation doesn't play。
@gpeal thanks your attention .in onBindViewHolder
@gpeal
https://pastebin.com/QYFjK26p here is a adapter's kotlin version
In item click I starting new activity and when I going back and try to click it again,lottie animation has stoped
@nullopp I also tested this case also,but I got same issue
@gpeal I'm using 2.7.0 version
@Bekakk Can you try with 3.0? There were several fixes that may have affected this
@gpeal
3.0 is a android x version ?
I try to update 3.0.0 ,but it's android x version.
My project does not support android X ,unfortunately.
Is a any way to use newest version without android X ?
best regards
@Bekakk No, you must upgrade to androidx but I suggest that you upgrade since most new libraries will require it. I think your issue will be fixed by some combination of that issue plus this PR
+1
@gpeal I am facing an opposite issue right now.
That is, if I play animation and scroll down in a RecyclerView before the animation finishes, and scroll back up, the animation plays from scratch again. I tried adding an animation listener and tried out some stuff in onAnimationCancel, such as setting the progress to 1f, pausing, cancelling, setting animation composition again, and a combination of these; but could not get it to work. I'm pretty sure it's not because of my logic to play animation (i.e. the code to start the animation does not get called again). I think it might internally be about the visibility changes that might be overriding anything I do.
What I want to do is, if the animation is cancelled, I just wanna set the progress to 100% and show that as a static image. This works for the initial onBindViewHolder calls, because I do a similar thing for showing the current state of the image. Any ideas what could be going wrong? Would appreciate any help, thanks!
+1
Most helpful comment
@gpeal I am facing an opposite issue right now.
That is, if I play animation and scroll down in a
RecyclerViewbefore the animation finishes, and scroll back up, the animation plays from scratch again. I tried adding an animation listener and tried out some stuff inonAnimationCancel, such as setting the progress to1f, pausing, cancelling, setting animation composition again, and a combination of these; but could not get it to work. I'm pretty sure it's not because of my logic to play animation (i.e. the code to start the animation does not get called again). I think it might internally be about the visibility changes that might be overriding anything I do.What I want to do is, if the animation is cancelled, I just wanna set the progress to 100% and show that as a static image. This works for the initial
onBindViewHoldercalls, because I do a similar thing for showing the current state of the image. Any ideas what could be going wrong? Would appreciate any help, thanks!