ViewAnimationUtils知识点

今天看到了一个视图慢慢显示出来的动画,心生好奇,决定一探究竟,原来,实现非常简单,使用ViewAnimationUtils. createCircularReveal()方法可以实现,这个方法返回一个动画器,该动画器可以使剪贴圆具有动画效果。具体代码如下:

    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) { }
            });
        }
    });

 

posted @ 2019-06-03 17:14  Ayinger  阅读(215)  评论(0编辑  收藏  举报