Api 21 Circular Reveal Animation not working

I can't get the circular disclosure animation to work. I think I checked the most obvious things: It starts, width and height> 0, and this can be seen, without exception ..

I download some data from the Internet and display it in the (fab) view. The animation should only play after the download is complete.

TmdbHelper helper = new TmdbHelper();
                helper.getMovieById(id, "en", new TmdbHelper.ResultListener() {
                    @Override
                    public void onResultReceived(JSONObject result) {

                        // called when finished downloading

                        try {
                            String rating = result.getString("vote_average");

                            AnimationHelper.circularReveal(fab, 500, 0); 

                            fab.setText(rating);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                });

AnimationHelper:

    public static void circularReveal(final View view, final long duration, long startDelay) {

    // get the center for the clipping circle
    int cx = (view.getLeft() + view.getRight()) / 2;
    int cy = (view.getTop() + view.getBottom()) / 2;

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

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

    anim.setDuration(duration);
    anim.setStartDelay(startDelay);

    anim.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

            view.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {}
    });

    // make the view visible and start the animation

    anim.start();
}

I use circular disclosure animation in other parts like this to make sure the view is attached and it works:

headerContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    headerContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    AnimationHelper.circularReveal(headerContainer, 500, 200);
                }
            });
+4
source share
2 answers

Perhaps you should erase this line inside yours onResultRecieved():

fab.setVisibility(View.VISIBLE);

, . - , FAB , .

, , , fab.setVisibility(View.VISIBLE), .

0

1- : .

                getWindow().getSharedElementExitTransition().addListener(new Transition.TransitionListener() {
                    @Override
                    public void onTransitionStart(Transition transition) {

                    }

                    @Override
                    public void onTransitionEnd(Transition transition) {

                    }

                    @Override
                    public void onTransitionCancel(Transition transition) {

                    }

                    @Override
                    public void onTransitionPause(Transition transition) {

                    }

                    @Override
                    public void onTransitionResume(Transition transition) {

                    }
                });

2- : , ,

    if (Build.VERSION.SDK_INT >= 21) {
        Animator anim = ViewAnimationUtils.createCircularReveal(viewRoot, cx, cy, 0, finalRadius);
        anim.setStartDelay(300);
        anim.setDuration(1000);
        anim.setInterpolator(new DecelerateInterpolator());
        anim.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

                viewRoot.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {

            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        anim.start();
    }
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        anim.start();
0

All Articles