揭露动画ViewAnimationUtils.createCircularReveal()

当您显示或隐藏一组 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和之前的动画使用没什么区别,同样可以设置监听器和加速器来实现各种各样的特效。这些效果常用在视图的添加,删除,状态,大小改变的时候。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值