Custom animation not called when using remove vs hide

I have a snippet that I want to slide to the left when it opens and slides to the right when we close it. The show part works fine, but when we close it, it works if I use hide (), but I want to remove the fragment so that it doesn't show when the configuration changes, etc., but then the same animation working for hide, doesn't work when remove () is called. See code below.

This code works, it shows that the panel goes into the desired animation

Fragment fragment = getFragmentManager().findFragmentByTag(Tags.PANEL_FRAGMENT_TAG.name());
        if (fragment != null) {
            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.setCustomAnimations(R.animator.slide_in_right, R.animator.slide_out_right);
            transaction.hide(fragment);
            transaction.commit();
        }

      

This code doesn't work. Any pointers? How can I remove the fragment and the animation is still working.

 Fragment fragment = getFragmentManager().findFragmentByTag(Tags.PANEL_FRAGMENT_TAG.name());
            if (fragment != null) {
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.setCustomAnimations(R.animator.slide_in_right, R.animator.slide_out_right);
                **transaction.remove(fragment);**
                transaction.commit();
            }

      

+3


source to share


1 answer


I found the reason in another post on stackoverflow which makes perfect sense

Here is the original post How to format deleting fragments



Rationale:

"The output view is animated on the input view canvas, so if there is no input canvas, there is no canvas to animate.

To show the animation, I should always use replace and use the input slices the same size as the output ones. After the animation When I finished, I decided that the new fragments would disappear. "

+1


source







All Articles