我有一个片段,这是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)mit(); 删除片段,当 lottie 动画已结束.如果在 isAnimating() Lottie方法返回false时我理解正确,则动画已经结束,并且由于在我的配置中动画不循环,这是我应该删除当前片段的时候.但是我不能只使用if语句,因为执行该动画时,动画可能仍会继续运行.
I need to remove the fragment using getActivity().getSupportFragmentManager().beginTransaction().remove(this)mit(); 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.
我需要一种在乐蒂动画结束时删除片段的方法,该怎么办?
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)mit(); } 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 :)
更多推荐
如何知道抽奖动画何时完成?
发布评论