新手发帖,很多方面都是刚入门,有错误的地方请大家见谅,欢迎批评指正
一、描述:
我们在计设动画时,常通都市用到一些Interpolator,而它的作用就是控制动画的速度,即可以理解为:
Interpolator是一个速度控制器,控制速度变更。
Interpolator口借只有一个抽象方法getInterpolation(float input),而统系也自带了几个Interpolater供我们应用:
1. AccelerateInterpolator: 动画从开始到结束,变更率是一个速加的进程。
2. DecelerateInterpolator: 动画从开始到结束,变更率是一个减速的进程。
3. CycleInterpolator: 动画从开始到结束,变更率是循环给定数次的正弦曲线。
4. AccelerateDecelerateInterpolator: 动画从开始到结束,变更率是先速加后减速的进程。
5. LinearInterpolator: 动画从开始到结束,变更率是线性变更。
除了以上几种,我们也可以承继Interpolater来义定自己的插补器:
import android.view.animation.Interpolator; public class MyInterpolator implements Interpolator { private float mFactor; private int iFactor; public MyInterpolator(int factor) { this.iFactor = factor; } @Override public float getInterpolation(float input) { switch (iFactor) { case 1: mFactor = input; // 性线匀速 break; case 2: mFactor = input * input * input; // 速加 break; } return mFactor; } }
二、Interpolater — 略策模式:
2.1 接口类:TimeInterpolator
package android.animation; /** * A time interpolator defines the rate of change of an animation. This allows animations * to have non-linear motion, such as acceleration and deceleration. */ public interface TimeInterpolator { /** * Maps a value representing the elapsed fraction of an animation to a value that represents * the interpolated fraction. This interpolated value is then multiplied by the change in * value of an animation to derive the animated value at the current elapsed animation time. * * @param input A value between 0 and 1.0 indicating our current point * in the animation where 0 represents the start and 1.0 represents * the end * @return The interpolation value. This value can be more than 1.0 for * interpolators which overshoot their targets, or less than 0 for * interpolators that undershoot their targets. */ float getInterpolation(float input); }
讲的很清晰:TimeInterpolator义定了一个可以转变动画速率的间时插补器,它许允你的动画可以非是线性行为:如速加和减速。
2.2 Interpolator:
package android.view.animation; import android.animation.TimeInterpolator; /** * An interpolator defines the rate of change of an animation. This allows * the basic animation effects (alpha, scale, translate, rotate) to be * accelerated, decelerated, repeated, etc. */ public interface Interpolator extends TimeInterpolator { // A new interface, TimeInterpolator, was introduced for the new android.animation // package. This older Interpolator interface extends TimeInterpolator so that users of // the new Animator-based animations can use either the old Interpolator implementations or // new classes that implement TimeInterpolator directly. }
我擦!想必大家都无语,只是告知我们Interpolater扩展了TimeInterpolator,其它什么都没。
2.3 插补器
头开经已分析了几种统系自带的,也举了个自义定的类,这些都没有任何关系,只不过提供给开发者,我有几种略策给你用,而你只要要在Animation中,set一下就行,其它的就交给Animation帮你去实现你想要的动画果效。
三、结总:
getInterpolation(float input)中的input是从哪里来的?
它是由Animation类在getTransformation中会调用getInterpolater,input = (当前间时-开始间时)/总时长;
即在TimeInterpolator中义定input = [0.0f, 1.0f]区间。
关于Animation,我会空抽讲授它。
文章结束给大家分享下程序员的一些笑话语录:
IT业众生相
第一级:神人,天资过人而又是技术狂热者同时还拥有过人的商业头脑,高瞻远瞩,技术过人,大器也。如丁磊,求伯君。
第二级:高人,有天赋,技术过人但没有过人的商业头脑,通常此类人不是顶尖黑客就是技术总监之流。
第三级:牛人,技术精湛,熟悉行业知识,敢于创新,有自己的公司和软件产品。
第四级:工头,技术精湛,有领导团队的能力,此类人大公司项目经理居多。
第五级:技术工人,技术精湛,熟悉行业知识但领导能力欠加,此类人大多为系分人员或资深程序员,基本上桀骜不逊,自视清高,不愿于一般技术人员为伍,在论坛上基本以高手面目出现。
第六级:熟练工人,技术有广度无深度,喜欢钻研但浅尝辄止。此类人大多为老程序员,其中一部分喜欢利用工具去查找网上有漏洞的服务器,干点坏事以获取成绩感。如果心情好,在论坛上他们会回答菜鸟的大部分问题。此级别为软件业苦力的重要组成部分。
第七级:工人,某些技术较熟练但缺乏深度和广度,此类人大多为程序员级别,经常在论坛上提问偶尔也回答菜鸟的问题。为软件产业苦力的主要组成部分。
第八级:菜鸟,入门时间不长,在论坛上会反复提问很初级的问题,有一种唐僧的精神。虽然招人烦但基本很可爱。只要认真钻研,一两年后就能升级到上一层。
第九级:大忽悠,利用中国教育的弊病,顶着一顶高学历的帽子,在小公司里混个软件部经理,设计不行,代码不行,只会胡乱支配下属,拍领导马屁,在领导面前胡吹海侃,把自己打扮成技术高手的模样。把勾心斗角的办公室文化引入技术部门,实在龌龊!
第十级:驴或傻X,会写SELECT语句就说自己精通ORALCE,连寄存器有几种都不知道就说自己懂汇编,建议全部送到日本当IT产业工人,挣了日本人的钱还严重打击日本的软件业!