• 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分钟后才能看到一个短暂停顿

  • 相关阅读:
    爬虫案例
    伪静态
    HTTP0.9、HTTP1.0、HTTP1.1、HTTP2的区别
    正向代理和反向代理
    数据结构继承
    APP 爬虫
    算法基础
    matplotlib
    Java类加载机制及自定义加载器
    SpringBoot war包部署到Tomcat服务器
  • 原文地址:https://www.cnblogs.com/ice5/p/13834688.html
Copyright © 2020-2023  润新知