ozodrukh / CircularReveal

Lollipop ViewAnimationUtils.createCircularReveal for everyone 4.0+
MIT License
2.43k stars 391 forks source link

CircularReveal when a fragment is opened #37

Closed monossido closed 8 years ago

monossido commented 9 years ago

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);
                }
            }
        });```
ozodrukh commented 9 years ago

Check this out i made a little sample

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

monossido commented 9 years ago

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.

juankysoriano commented 9 years ago

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

jpardogo commented 9 years ago

+1

ozodrukh commented 9 years ago

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?

ayaseruri commented 9 years ago

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

andrey-shikhov commented 9 years ago

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 }

sergejsha commented 8 years ago

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);
            }
        });
amanzan commented 8 years ago

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

ozodrukh commented 8 years ago

updated examples take a look

jinsen47 commented 8 years ago

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

ozodrukh commented 8 years ago

u can create and start animation in onPreDraw method

jinsen47 commented 8 years ago

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

ozodrukh commented 8 years ago

it was just example of using setStartDelay method :sweat_smile: 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