ViewAnimationUtils knowledge

Today saw a view to slowly appear animated, Heart of curiosity, decided to check it out, the original, very simple to implement, use ViewAnimationUtils. CreateCircularReveal () method can be implemented, this method returns an animator, the animation can make the clip round animate. Specific code as follows:

    final View view = findViewById(R.id.view);
    view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @RequiresApi(api = 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) {
            int x = (int) (view.getWidth() / 2 );
            int y = (int) (view.getHeight() / 2 );
            // x,y 是动画圆心点
            Animator animator = ViewAnimationUtils.createCircularReveal(view, x, y,
                    0,view.getHeight());
            animator.setDuration(4000);
            animator.start();
            animator.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) { }
    
                @Override
                public void onAnimationEnd(Animator animation) {
                    view.setVisibility(View.GONE);
                }
    
                @Override
                public void onAnimationCancel(Animator animation) { }
    
                @Override
                public void onAnimationRepeat(Animator animation) { }
            });
        }
    });

 

Guess you like

Origin www.cnblogs.com/Ayinger/p/10968773.html