Android动画的灵魂舞曲(三)

插值器(Interpolator)

在之前的章节,我们已经对动画已经有了一部分的了解了。那么这里我们要先讲讲插值器(Interpolator)。以加深我们对动画的理解。

以下是给动画添加系统的插值器的资源id:

Interpolator class Resource ID
AccelerateDecelerateInterpolator @android:anim/accelerate_decelerate_interpolator
AccelerateInterpolator @android:anim/accelerate_interpolator
AnticipateInterpolator @android:anim/anticipate_interpolator
AnticipateOvershootInterpolator @android:anim/anticipate_overshoot_interpolator
BounceInterpolator @android:anim/bounce_interpolator
CycleInterpolator @android:anim/cycle_interpolator
DecelerateInterpolator @android:anim/decelerate_interpolator
LinearInterpolator @android:anim/linear_interpolator
OvershootInterpolator @android:anim/overshoot_interpolator

而对于每个插值器的能够带来的效果:

Interploator class decription
AccelerateDecelerateInterpolator 开始和结束缓慢,中间加速
AccelerateInterpolator 开始的时候缓慢,之后开始加速
AnticipateInterpolator 开始的时候向后甩一下,然后向前
AnticipateOvershootInterpolator 开始的时候向后甩一下,然后加速向前甩过终点一点后回到原点
BounceInterpolator 动画结束的时候小距离的时候在终点处弹起
CycleInterpolator 将重复周期的指定数目的动画。变化率遵循正弦模式。
DecelerateInterpolator 开始的时候快,结束的时候慢
LinearInterpolator 以常量速率变化
OvershootInterpolator 运动到终点后,冲过终点后再回弹

若是系统提供的插值器不能满足你的业务需求,那么也是可以自己定义一部分属性的:
<accelerateInterpolator>

android:factor Float型,加速度值(默认是1)

<anticipateInterpolator>

android:tension Float型,张力的值(默认是2)。可以理解为来回弹的幅度

<anticipateOvershootInterpolator>

android:tension Float型,张力的值(默认是2)
android:extraTension Float型,张力的倍数(默认是1.5)

<cycleInterpolator>

android:cycles Integer型,周期的数目(默认是1)

<decelerateInterpolator>

android:factor Float型,减速度(默认是1)

<overshootInterpolator>

android:tension Float型,张力的值(默认是2)

通过xml实现的方式:

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1500"
    android:fromXDelta="0"
    android:fromYDelta="0"    
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:toXDelta="300"
    android:toYDelta="300"></translate>

通过java代码实现的方式:

animation.setInterpolator(new AccelerateDecelerateInterpolator());
viewBtn.startAnimation(animation);
AccelerateDecelerateInterpolator
AccelerateDecelerateInterpolator
DecelerateInterpolator
DecelerateInterpolator.gif
AnticipateInterpolator
AnticipateInterpolator
BounceInterpolator
BounceInterpolator
LinearInterpolator
LinearInterpolator
OvershootInterpolator
OvershootInterpolator
CycleInterpolator
CycleInterpolator
AccelerateInterpolator
AccelerateInterpolator
AnticipateOvershootInterpolator
AnticipateOvershootInterpolator

以上就是视图动画的学习总结,总结出来可能有遗漏或者错误,欢迎指正个人总结。转载请注明出处http://www.jianshu.com/p/1b9cc1e658af

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 转载一篇高质量博文,原地址请戳这里转载下来方便今后查看。1 背景不能只分析源码呀,分析的同时也要整理归纳基础知识,...
    Elder阅读 1,968评论 0 24
  • 1 背景 不能只分析源码呀,分析的同时也要整理归纳基础知识,刚好有人微博私信让全面说说Android的动画,所以今...
    未聞椛洺阅读 2,777评论 0 10
  • 在故里, 我们,向阳而生, 草木,和衣而睡。 一条黄狗, 与白房子交以赤诚。 在故里, 家狗,荷月不归, 鸡舍,星...
    归舴阅读 601评论 8 20
  • "其实,我不想再多做解释了。" 小j讲这句话时,我能察觉到她淡然的神情下的一丝苦不堪言。 ...
    super凌阅读 559评论 0 1
  • 独身夜中央, 起身茶已凉。 昨日梦中语, 如今两苍茫。
    a烟火阅读 218评论 1 0