Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Circular reveal animation while replacing fragment

I wonder how to make a circular reveal animation while replacing fragment.

I'm using this code to replace my fragment :

        getFragmentManager()
            .beginTransaction()
            .replace(R.id.mission_detail_appointment_container, new AppointmentDeclineFragment())
            .commit();

And I got this code to do the circular reveal animation:

Animator anim = ViewAnimationUtils.createCircularReveal(appointmentContainer, (int)motionEventX, (int)motionEventY, 0, finalRadius);
anim.start();

Is there any way to launch the animator when I replace my fragment ? I just saw the setCustomAnimation method but it takes int resources as argument and I go an Animator object.

Thanks for your help

like image 928
Thomas Avatar asked Jun 20 '16 13:06

Thomas


1 Answers

I finally find a workaround. For those who might need it, that's the way I decided to implement my circular reveal animation in fragments.

By adding a onLayoutChangeListener in the onCreateView method of my fragments:

 view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {

            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                v.removeOnLayoutChangeListener(this);
                int cx = getArguments().getInt(MOTION_X_ARG);
                int cy = getArguments().getInt(MOTION_Y_ARG);
                int width = getResources().getDimensionPixelSize(R.dimen.fragment_appointment_width);
                int height = getResources().getDimensionPixelSize(R.dimen.fragment_appointment_height);

                float finalRadius = Math.max(width, height) / 2 + Math.max(width - cx, height - cy);
                Animator anim = ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, finalRadius);
                anim.setDuration(500);
                anim.start();
            }
        });
like image 100
Thomas Avatar answered Oct 27 '22 06:10

Thomas