zoukankan      html  css  js  c++  java
  • (原)android补间动画(四)之插补器Interpolator

    比如说一段旋转动画

    RotateAnimation animation = new RotateAnimation(0, 360,
                    mMoveCircle.getMeasuredWidth() / 2,
                    mMoveCircle.getMeasuredHeight() / 2);
    animation.setDuration(1000);
    animation.setRepeatCount(3);//共转4圈

    这样设定好animation对象后就已经可以用了

    mView.startAnimation(animation);

    但是会发现旋转过程并非完全匀速

    如果我们想要让它完全匀速地旋转,或者加速旋转,或者任何我们想要的速度效果

    那么这个时候就可以使用插补器了

    例如:

    匀速:

    LinearInterpolator i = new LinearInterpolator();
    animation.setInterpolator(i);

    加速:

    AccelerateInterpolator i = new AccelerateInterpolator(3);

    animation.setInterpolator(i);

    遇障反弹:

    BounceInterpolator i = new BounceInterpolator();

    animation.setInterpolator(i);

    以及数个系统自带的效果(它们都是Interpolator接口的子类,可参阅SDK)

    如果想要更加客制化的效果,可以写自己的插补器

    例如,这里是用一个匿名类来实现的幂函数加速规则

     Interpolator i = new Interpolator() {
    
     @Override
     public float getInterpolation(float input) {
     // TODO Auto-generated method stub
     // return input*3;//总时长没变,转的圈数增加了
     return input*input;
     }
     };
  • 相关阅读:
    好用的视频播放器
    如何屏蔽weGame今日推荐窗口
    存一个大佬的地图编辑器
    过渡页面,加载进度
    Lua中正弦,余弦函数的使用
    如何替换loadingBar的底图
    使用精灵帧缓存替换纹理
    setTexture和loadTexture之间的区别
    我胡汉三又回来了
    python中单斜杆和双斜杠的区别
  • 原文地址:https://www.cnblogs.com/BlogCommunicator/p/4931462.html
Copyright © 2011-2022 走看看