揭露动画ViewAnimationUtils.createCircularReveal()

来源:互联网 发布:硬盘坏了恢复数据 编辑:程序博客网 时间:2024/05/18 01:02

当您显示或隐藏一组 UI 元素时,揭露动画可为用户提供视觉连续性。ViewAnimationUtils.createCircularReveal() 方法让您能够为裁剪区域添加动画以揭露或隐藏视图。

应用ViewAnimationUtils.createCircularReveal()方法可以去创建一个RevealAnimator动画。

ViewAnimationUtils.createCircularReveal源码如下:

 * @param view The View will be clipped to the animating circle.视图     * @param centerX The x coordinate of the center of the animating circle, relative to     *                <code>view</code>.动画开始的中心点X     * @param centerY The y coordinate of the center of the animating circle, relative to     *                <code>view</code>.动画开始的中心点Y     * @param startRadius The starting radius of the animating circle.动画开始半径     * @param endRadius The ending radius of the animating circle动画结束半径public static Animator createCircularReveal(View view,          int centerX,  int centerY, float startRadius, float endRadius) {      return new RevealAnimator(view, centerX, centerY, startRadius, endRadius);  }
实例代码在onCreate方法中执行动画,控件的宽高还没有计算出来,调用view的post方法。
<ImageView        android:background="@color/colorPrimary"        android:id="@+id/iv_reveal"        android:layout_width="150dp"        android:layout_height="150dp"        android:layout_gravity="center_horizontal"        android:layout_marginTop=“100dp"/>
 final ImageView ivReveal = (ImageView) findViewById(R.id.iv_reveal);ivReveal.post(new Runnable() {                @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)                @Override                public void run() {                    //隐藏                    Animator animation = ViewAnimationUtils.createCircularReveal(ivReveal,     ivReveal.getWidth() / 2,                            ivReveal.getHeight() / 2, ivReveal.getWidth() / 2, 0);                    animation.setInterpolator(new AccelerateDecelerateInterpolator());                    animation.setDuration(1500).start();                    animation.addListener(new AnimatorListenerAdapter() {                        @Override                        public void onAnimationEnd(Animator animation) {                            super.onAnimationEnd(animation);                            ivReveal.setVisibility(View.INVISIBLE);                        }                    });//                    //显示//                    Animator animation = ViewAnimationUtils.createCircularReveal(ivReveal, 0,//                            0, 0 ,ivReveal.getHeight()/2);//                    animation.setInterpolator(new AccelerateInterpolator());//                    animation.setDuration(1500).start();                }            });

RevealAnimator和之前的动画使用没什么区别,同样可以设置监听器和加速器来实现各种各样的特效。这些效果常用在视图的添加,删除,状态,大小改变的时候。

原创粉丝点击