android 圆形展开/关闭动画

参考自:高仿哔哩哔哩客户端的SearchView http://www.jianshu.com/p/e0a6fc621945
这里写图片描述
开关点击:

CircleAnimateUtils.handleAnimate(txt);

圆形动画工具类:

public class CircleAnimateUtils {
    public static void handleAnimate(final View animateView) {
        //隐藏
        if (animateView.getVisibility() == View.VISIBLE) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                /**
                 * createCircularReveal 方法参数
                 * view 执行动画的view
                 * centerX 圆心横坐标
                 * centerY 圆心纵坐标
                 * startRadius 动画开始时圆的半径
                 * endRadius 动画结束时圆的半径
                 */
                final Animator animatorHide = ViewAnimationUtils.createCircularReveal(animateView,
                        0,
                        0,
                        //确定圆的半径(算长宽的斜边长,这样半径不会太短也不会很长效果比较舒服)
                        (float) Math.hypot(animateView.getWidth(), animateView.getHeight()),
                        0);
                animatorHide.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        animateView.setVisibility(View.GONE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                animatorHide.setDuration(300);
                animatorHide.start();
            } else {
                animateView.setVisibility(View.GONE);
            }
            animateView.setEnabled(false);
        }
        //显示
        else {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                final Animator animator = ViewAnimationUtils.createCircularReveal(animateView,
                        0,
                        0,
                        0,
                        (float) Math.hypot(animateView.getWidth(), animateView.getHeight()));
                animator.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        animateView.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {

                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                animator.setDuration(300);
                animator.start();
            } else {
                animateView.setVisibility(View.VISIBLE);
            }
            animateView.setEnabled(true);
        }
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值