本文介绍了如何知道 Lottie 动画何时完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个片段,这里是 onCreateView 方法:

I have a fragment, here is the onCreateView method:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    mView = inflater.inflate(R.layout.fragment_added_to_cart_anim, container, false);
    ButterKnife.bind(this, mView);

    mAddedToCartAnimation.setAnimation("checked_done_.json");
    mAddedToCartAnimation.loop(false);
    mAddedToCartAnimation.playAnimation();

    // Remove fragment when the animation is finished.

    return mView;

}

我需要使用 getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit();lottie 动画已结束.如果我在 isAnimating() Lottie 方法返回 false 时理解正确,则动画已结束,并且由于在我的配置中动画不会循环,此时我应该删除当前片段.但我不能只使用 if 语句,因为当它执行时,动画可能仍在运行.

I need to remove the fragment using getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit(); when the lottie animation has ended. If I understand correctly when the isAnimating() Lottie method returns false the animation has ended and since in my configuration the animation does not loop this is when I should remove the current fragment. But I can't just use an if statement since when it is executed the animation may still be going.

我需要一种在 Lottie 动画结束时移除片段的方法,我该怎么做?

I need a way to remove the fragment when the Lottie animation ends, how do I do this?

推荐答案

这段代码对我有用:

mAddedToCartAnimation.addAnimatorListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            Log.e("Animation:","start");
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            Log.e("Animation:","end");
            //Your code for remove the fragment
            try {
                getActivity().getSupportFragmentManager()
                      .beginTransaction().remove(this).commit();
            } catch(Exception ex) {
                ex.toString();
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            Log.e("Animation:","cancel");
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            Log.e("Animation:","repeat");
        }
    });

我希望这能解决您的问题:)

I hope this solve your problem :)

这篇关于如何知道 Lottie 动画何时完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 04:01