Android 设置动画变化的速率

我们知道 Android 的动画有视图动画,属性动画,帧动画等等,对于视图动画我们是可以设置动画的变化速率的,有加速,减速,先加速再减速…等等各种变化速率的效果。对于视图动画,创建动画有两种方式,一种是在 xml 文件中创建,另一种是在代码中创建,因此对应的设置动画变化速率也有两种方式。

一、xml 中设置动画的变化速率

1.设置动画为加速动画(动画播放中越来越快):

android:interpolator="@android:anim/accelerate_interpolator"

2.设置动画为减速动画(动画播放中越来越慢) :

android:interpolator="@android:anim/decelerate_interpolator"

3.设置动画为先加速在减速(开始速度最快 逐渐减慢):

android:interpolator="@android:anim/accelerate_decelerate_interpolator"

4.先反向执行一段,然后再加速反向回来(相当于我们弹簧,先反向压缩一小段,然后在加速弹出):

android:interpolator="@android:anim/anticipate_interpolator"

5.同上先反向一段,然后加速反向回来,执行完毕自带回弹效果(更形象的弹簧效果):

android:interpolator="@android:anim/anticipate_overshoot_interpolator"

6.执行完毕之后会回弹跳跃几段(相当于我们高空掉下一颗皮球,到地面是会跳动几下):

android:interpolator="@android:anim/bounce_interpolator"

7.循环,动画循环一定次数,值的改变为一正弦函数:Math.sin(2* mCycles* Math.PI* input):

android:interpolator="@android:anim/cycle_interpolator"

8.线性均匀改变:

android:interpolator="@android:anim/linear_interpolator"

9.加速执行,结束之后回弹:

android:interpolator="@android:anim/overshoot_interpolator"

二、代码中设置动画的变化速率

1.设置动画为加速动画(动画播放中越来越快):

animation.setInterpolator(new AccelerateInterpolator());

2.设置动画为减速动画(动画播放中越来越慢) :

animation.setInterpolator(new DecelerateInterpolator());

3.设置动画为先加速在减速(开始速度最快 逐渐减慢):

animation.setInterpolator(new AccelerateDecelerateInterpolator());

4.先反向执行一段,然后再加速反向回来(相当于我们弹簧,先反向压缩一小段,然后在加速弹出):

animation.setInterpolator(new AnticipateInterpolator());

5.同上先反向一段,然后加速反向回来,执行完毕自带回弹效果(更形象的弹簧效果):

animation.setInterpolator(new AnticipateOvershootInterpolator());

6.执行完毕之后会回弹跳跃几段(相当于我们高空掉下一颗皮球,到地面是会跳动几下):

animation.setInterpolator(new BounceInterpolator());

7.循环,动画循环一定次数,值的改变为一正弦函数:Math.sin(2* mCycles* Math.PI* input):

animation.setInterpolator(new CycleInterpolator(2));

8.线性均匀改变:

animation.setInterpolator(new LinearInterpolator());

9.加速执行,结束之后回弹:

animation.setInterpolator(new OvershootInterpolator());

如果觉得文章不错或者有帮到你的话,欢迎大家点赞和评论!

你还可以在下面这些地方也可以找到我:

微信公众号:「IT大飞说」
GitHub:https://github.com/xinpengfei520
CSDN:https://blog.csdn.net/xinpengfei521
简书:https://www.jianshu.com/u/268aa8e1a12f
掘金:https://juejin.im/user/57c82d0779bc440063eac0f8
CnBlog:https://www.cnblogs.com/angel88/
知乎:https://www.zhihu.com/people/xin-peng-fei-9/activities
微博:https://weibo.com/u/1783451275?is_all=1
Blog:http://www.x-sir.com

本文首发于我的微信公众号,更多干货文章,请扫描二维码订阅哦:

您可以扫描屏幕右侧的二维码,来关注我的微信公众号,来学习更多的干货文章!

另外,我还建了一个免费的知识星球,感兴趣的微信扫码即可加入!

image

更多相关文章

  1. Android Animation动画实战(一): 从布局动画引入ListView滑动时,每一
  2. Android中播放Gif动画取巧的办法
  3. Android实现ProgressBar旋转菊花加载的动画
  4. Android Animation动画详解(二): 组合动画特效
  5. android XML动画初步解析(activity界面之间跳转demo)
  6. Android应用资源---动画资源(Animation Resources)(三)
  7. Android 系统锁屏实现固件升级动画
  8. Android 高级UI解密 (四) :花式玩转贝塞尔曲线(波浪、轨迹变换动画

随机推荐

  1. 浅谈Android中MVC、MVP、MVVM模式(一)
  2. iPhone和Android,谁将成为赢家?
  3. android连接webapp发送接收消息最简实现
  4. android shape的使用详解
  5. sdcardFS(android sdcard存储方案---基于w
  6. Android中如何修改编译的资源ID值(默认值
  7. Android与设计模式浅谈
  8. 最新!!Android 状态栏详细开发,5分钟精通状
  9. Android Opengl开发一
  10. 打造android万能上拉下拉刷新框架——XRe