ozodrukh/CircularReveal

CircularReveal when a fragment is opened

Closed this issue · 14 comments

I'm tring to have a CircularReveal on an ImageView when a fragment is opened.

I know that in order to measure views in fragment I have to call addOnGlobalLayoutListener and inside onGlobalLayout I can measure views.
I can see the correct width/height ecc... but the ImageView never shows up.

       vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            public boolean alreadMeasure = false;

            @Override
            public void onGlobalLayout() {
                if (!alreadMeasure) {
                 int cx = (myView.getWidth()) / 2;
                 int cy = (myView.getHeight()) / 2;

                 int finalRadius = Math.max(myView.getWidth(), myView.getHeight());

                 SupportAnimator animator =
                ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
                 animator.setInterpolator(new AccelerateDecelerateInterpolator());
                 animator.setDuration(800);
                animator.start();
                    alreadMeasure = true;
                } else {
                    view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                }
            }
        });```

Check this out i made a little sample

https://gist.github.com/ozodrukh/c9343e7073907c5c5d2c

Ok, I tried to align my code to the sample ,without success.
But I've noticed that on an emulator with android 4.2 it works!
Only on my phone, with android 5.1 (cm 12.1) it doesn't work at all.

I have the same issue as @monossido; not working on Lollipop but working on pre-lollipop.

+1

Hm interesting but it works smooth on my Motorola XT1032(5.1) and emulators(5.0, 5.1)
Could you build and install sample.apk and provide information how it works?

I have the same issue as @monossido; not working on Lollipop but working on pre-lollipop.

I can confirm, this is not working on lollipop fragments, at least on nested ones. Tested on android emulator 5.0.1, 5.1.1 and samsung galaxy s6 edge
Workaround:
if(LOLLIPOP)
{
// this is native apis, not library ones
Animator circularReveal = android.view.ViewAnimationUtils.createCircularReveal(targetView, cx, cy, 0, r);
circularReveal.start();
}
else
{
// use backported api
}

I use this code right after showing a fragment on Android 6.0 and it works like a charm

    mContainer.getViewTreeObserver().addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override public void onGlobalLayout() {
                int size = Math.max(mContainer.getWidth(), mContainer.getHeight());
                if (size == 0) return;

                // create and start animation
                ...

                // it is important to remove listener
                mContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        });

@beworker , could you please share your complete working example?

updated examples take a look

Hi, I 'm trying to make a reveal animation when a fragment is opened.
I implemented in onHiddenChanged function( create animator in onPreDraw, and start in onHiddenChanged), but nothing happened.
Do u have any idea?
Thanks

u can create and start animation in onPreDraw method

@ozodrukh I tried your method, and I found the animation.startDelay(100) is essential, could you tell me why?

it was just example of using setStartDelay method 😅 and if u haven't noticed by delaying animation start it first white screen flash and after animation starts, i suggest u starting animation in onPreDraw() method