zoukankan      html  css  js  c++  java
  • android RotateAnimation无限旋转

    先上代码:

    RotateAnimation animation =new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    animation.setDuration(3000); #3000毫秒旋转一周
    animation.setRepeatCount(Animation.INFINITE); #无限循环
    animation.setInterpolator(new LinearInterpolator()); #匀速圆周运动
    animation.setFillAfter(true);
    getView(R.id.img).setAnimation(animation);

    运行后,能正常运行,但是发现,当图片循环一周后,会又一个非常小间隙的停顿。原因在于,每个周期运行完后,会重新旋转,这个间隙造成了停顿。

    如何解决这个问题?答案就在代码标红部分。

    360f 表示从0度旋转到360度,即一个周期的角度,运行时间是3000毫秒。如果是一个周期结束后重新开始造成的短暂停顿,那么,将一个周期的旋转角度增加呢?

    重写代码:

    int multiple=1000;//增加1000倍
    float endDegrees=360f * multiple;
    long duration=3000 * multiple;
    RotateAnimation animation =new RotateAnimation(0f, endDegrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    animation.setDuration(duration);
    animation.setRepeatCount(Animation.INFINITE); //无限循环
    animation.setInterpolator(new LinearInterpolator());
    animation.setFillAfter(true);
    getView(R.id.test).setAnimation(animation);

    此时的一个旋转周期是3000秒,也就是50分钟后才能看到一个短暂停顿

  • 相关阅读:
    hdu 4786 Fibonacci Tree
    Sae 上传文件到Storage
    Java通过代理server上网
    iOS 利用Socket UDP协议广播机制的实现
    android_handler(三)
    shell 脚本执行日志通用模块
    adt-bundle-linux-x86_64-20131030下新建project提示找不到adb和R.java问题的解决
    【MongoDB】The Access control of mongodb
    Java——设计模式(装饰模式_IO)
    动态顺序表
  • 原文地址:https://www.cnblogs.com/ice5/p/13834688.html
Copyright © 2011-2022 走看看