Android L reveal Effect is not working

别说谁变了你拦得住时间么 提交于 2019-12-04 03:44:23

I am also facing the issue as I mentioned and I am able to resolve this issue by getting cx and cy the center position for image view (In your case I think it is button).
So get cx and cy using this:

int cx = (fabBtn.getWidth()) / 2;
int cy = (fabBtn.getHeight()) / 2;

Instead of this::

int cx = (fabBtn.getLeft() + fabBtn.getRight()) / 2;
int cy = (fabBtn.getTop() + fabBtn.getBottom()) / 2;

You might be calling getWidth() and getHeight() too soon.

So you'll have to use a getViewTreeObserver()

Be sure to add a duration to anim.setDuration(time) and set the initial visibility of the view to INVISIBLE

Here the code:

public void checker() {
    myView.getViewTreeObserver().addOnPreDrawListener(
            new ViewTreeObserver.OnPreDrawListener() {
                public boolean onPreDraw() {
                    int finalHeight = myView.getMeasuredHeight();
                    int finalWidth = myView.getMeasuredWidth();
                    // Do your work here
                    myView.getViewTreeObserver().removeOnPreDrawListener(this);

                    cx = finalHeight / 2;
                    cy = finalWidth / 2;


                    finalRadius = Math.max(finalHeight, finalWidth);
                    anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
                    myView.setVisibility(View.VISIBLE);
                    anim.setDuration(3000);
                    anim.start();


                    return true;
                }
            });

}
Valdrinit

I thought I had the same problem, but it seems that, for some reason, a duration of just 2000 milliseconds is not enough for the animation to show. When I set the duration to 3000, I saw a beautiful circle animation.

A small delay of 1 second also helped

                // get the center for the clipping circle
                int cx = myView.getWidth() / 2;
                int cy = myView.getHeight() / 2;

                // get the final radius for the clipping circle
                int finalRadius = Math.max(myView.getWidth(), myView.getHeight());

                // create the animator for this view (the start radius is zero)
                Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
                anim.setStartDelay(1000);

                // make the view visible when the animation starts
                anim.addListener(new AnimatorListenerAdapter()
                {
                    @Override
                    public void onAnimationStart(Animator animation)
                    {
                        super.onAnimationStart(animation);
                        myView.setVisibility(View.VISIBLE);
                    }
                });

                // start the animation
                anim.start();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!