fragment/src/main/java/androidx/fragment/app/FragmentManager.java
private void animateRemoveFragment(@NonNull final Fragment fragment,
            @NonNull AnimationOrAnimator anim, final int newState) {
        final View viewToAnimate = fragment.mView;
        final ViewGroup container = fragment.mContainer;
        container.startViewTransition(viewToAnimate);
        fragment.setStateAfterAnimating(newState);
        if (anim.animation != null) {
            Animation animation =
                    new EndViewTransitionAnimator(anim.animation, container, viewToAnimate);
            fragment.setAnimatingAway(fragment.mView);
            AnimationListener listener = getAnimationListener(animation);
            animation.setAnimationListener(new AnimationListenerWrapper(listener) {
                @Override
                public void onAnimationEnd(Animation animation) {
                    super.onAnimationEnd(animation);

                    // onAnimationEnd() comes during draw(), so there can still be some
                    // draw events happening after this call. We don't want to detach
                    // the view until after the onAnimationEnd()
                    container.post(new Runnable() {
                        @Override
                        public void run() {
                            if (fragment.getAnimatingAway() != null) {
                                fragment.setAnimatingAway(null);
                                moveToState(fragment, fragment.getStateAfterAnimating(), 0, 0,
                                        false);
                            }
                        }
                    });
                }
            });
            setHWLayerAnimListenerIfAlpha(viewToAnimate, anim);
            fragment.mView.startAnimation(animation);
        } else {
            Animator animator = anim.animator;
            fragment.setAnimator(anim.animator);
            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator anim) {
                    container.endViewTransition(viewToAnimate);
                    // If an animator ends immediately, we can just pretend there is no animation.
                    // When that happens the the fragment's view won't have been removed yet.
                    Animator animator = fragment.getAnimator();
                    fragment.setAnimator(null);
                    if (animator != null && container.indexOfChild(viewToAnimate) < 0) {
                        moveToState(fragment, fragment.getStateAfterAnimating(), 0, 0, false);
                    }
                }
            });
            animator.setTarget(fragment.mView);
            setHWLayerAnimListenerIfAlpha(fragment.mView, anim);
            animator.start();
        }
    }
/**
     * Animates the removal of a fragment with the given animator or animation. After animating,
     * the fragment's view will be removed from the hierarchy.
     *
     * @param fragment The fragment to animate out
     * @param anim The animator or animation to run on the fragment's view
     * @param newState The final state after animating.
     */
Animates the removal of a fragment with the given animator or animation. After animating,
the fragment's view will be removed from the hierarchy.

@param fragment The fragment to animate out
@param anim The animator or animation to run on the fragment's view
@param newState The final state after animating.
Animates the removal of a fragment with the given animator or animation . After animating the fragment ' s view will be removed from the hierarchy . @param fragment The fragment to animate out @param anim The animator or animation to run on the fragment ' s view @param newState The final state after animating .
private void animateRemoveFragment(@NonNull final Fragment fragment,
            @NonNull AnimationOrAnimator anim, final int newState) {
        final View viewToAnimate = fragment.mView;
        final ViewGroup container = fragment.mContainer;
        container.startViewTransition(viewToAnimate);
        fragment.setStateAfterAnimating(newState);
        if (anim.animation != null) {
            Animation animation =
                    new EndViewTransitionAnimator(anim.animation, container, viewToAnimate);
            fragment.setAnimatingAway(fragment.mView);
            AnimationListener listener = getAnimationListener(animation);
            animation.setAnimationListener(new AnimationListenerWrapper(listener) {
                @Override
                public void onAnimationEnd(Animation animation) {
                    super.onAnimationEnd(animation);
                    container.post(new Runnable() {
                        @Override
                        public void run() {
                            if (fragment.getAnimatingAway() != null) {
                                fragment.setAnimatingAway(null);
                                moveToState(fragment, fragment.getStateAfterAnimating(), 0, 0,
                                        false);
                            }
                        }
                    });
                }
            });
            setHWLayerAnimListenerIfAlpha(viewToAnimate, anim);
            fragment.mView.startAnimation(animation);
        } else {
            Animator animator = anim.animator;
            fragment.setAnimator(anim.animator);
            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator anim) {
                    container.endViewTransition(viewToAnimate);
                    Animator animator = fragment.getAnimator();
                    fragment.setAnimator(null);
                    if (animator != null && container.indexOfChild(viewToAnimate) < 0) {
                        moveToState(fragment, fragment.getStateAfterAnimating(), 0, 0, false);
                    }
                }
            });
            animator.setTarget(fragment.mView);
            setHWLayerAnimListenerIfAlpha(fragment.mView, anim);
            animator.start();
        }
    }
private void animateRemoveFragment ( @ NonNull final Fragment fragment , @ NonNull AnimationOrAnimator anim , final int newState ) { final View viewToAnimate = fragment . mView ; final ViewGroup container = fragment . mContainer ; container . startViewTransition ( viewToAnimate ) ; fragment . setStateAfterAnimating ( newState ) ; if ( anim . animation != null ) { Animation animation = new EndViewTransitionAnimator ( anim . animation , container , viewToAnimate ) ; fragment . setAnimatingAway ( fragment . mView ) ; AnimationListener listener = getAnimationListener ( animation ) ; animation . setAnimationListener ( new AnimationListenerWrapper ( listener ) { @ Override public void onAnimationEnd ( Animation animation ) { super . onAnimationEnd ( animation ) ; container . post ( new Runnable ( ) { @ Override public void run ( ) { if ( fragment . getAnimatingAway ( ) != null ) { fragment . setAnimatingAway ( null ) ; moveToState ( fragment , fragment . getStateAfterAnimating ( ) , 0 , 0 , false ) ; } } } ) ; } } ) ; setHWLayerAnimListenerIfAlpha ( viewToAnimate , anim ) ; fragment . mView . startAnimation ( animation ) ; } else { Animator animator = anim . animator ; fragment . setAnimator ( anim . animator ) ; animator . addListener ( new AnimatorListenerAdapter ( ) { @ Override public void onAnimationEnd ( Animator anim ) { container . endViewTransition ( viewToAnimate ) ; Animator animator = fragment . getAnimator ( ) ; fragment . setAnimator ( null ) ; if ( animator != null && container . indexOfChild ( viewToAnimate ) < 0 ) { moveToState ( fragment , fragment . getStateAfterAnimating ( ) , 0 , 0 , false ) ; } } } ) ; animator . setTarget ( fragment . mView ) ; setHWLayerAnimListenerIfAlpha ( fragment . mView , anim ) ; animator . start ( ) ; } }
Animates the removal of a fragment with the given animator or animation.
Animates the removal of a fragment with the given animator or animation .
// onAnimationEnd() comes during draw(), so there can still be some // draw events happening after this call. We don't want to detach // the view until after the onAnimationEnd() // If an animator ends immediately, we can just pretend there is no animation. // When that happens the the fragment's view won't have been removed yet.