Circular animation of disclosure when replacing a fragment

I wonder how to make a circular animation of the disclosure when replacing a fragment.

I use this code to replace my snippet:

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

And I got this code to make a circular animation:

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

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

thanks for the help

+4
source share
1 answer

I finally found a workaround. For those who may need it, the way I decided to implement my circular animation in fragments.

By adding onLayoutChangeListener to 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();
            }
        });
+14
source

All Articles