Android 动画-CircularReveal

来源:互联网 发布:淘宝返利哪里取消? 编辑:程序博客网 时间:2024/06/07 10:40

上篇已经记录了Android 5.0以上的转场共享动画的知识,这次在来整理一下另一个比较炫的动画:CircularReveal
CircularReveal也是MaterialDesign下的内容,也就是Android 5.0 API >= 21才能使用的。

一、实现

这里写图片描述

效果如上,是一个点击涟漪的感觉。代码实现也很简单:

Animator anim = ViewAnimationUtils.createCircularReveal(                view,                 (int) event.getX(),                (int) event.getY(),                 0,                (float) Math.hypot(v.getWidth(), v.getHeight()));        anim.setDuration(1000);          anim.setInterpolator(new AccelerateDecelerateInterpolator());        anim.start();

可见主要代码是createCircularReveal

public static Animator createCircularReveal (View view, int centerX,int centerY, float startRadius, float endRadius)

参数说明:

  1. View view, 指定了为哪个View执行动画
  2. int centerX, 涟漪效果的中心x轴位置
  3. int centerY, 涟漪效果的中心y轴位置
  4. float startRadius, 开始的半径
  5. float endRadius, 结束的半径

很简单的实现吧,但是这么简单代码在项目中可应用的效果还是不错的,上面的效果算是一个抛砖引玉吧,来看下实际应用的效果:

这里写图片描述

顶部的SearchView和底部的BottomNavigation都实现了这样的效果。

栗子详细代码,请点这里~

1 0
原创粉丝点击