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

  • 相关阅读:
    如何准备面试复试(1)
    如何应对糟糕的面试官(2)
    美国:经济危机让烟民吸烟量增加
    MOV 指令的注意事项
    一个简单的ajax无刷新翻页的程序
    SQL注入漏洞全接触
    php+mysql非暴力查表的注入语句写法总结
    在你的成长过程中,有五个人非常重要
    爱就在那里,不增不减
    php的一些书籍
  • 原文地址:https://www.cnblogs.com/ice5/p/13834688.html
Copyright © 2020-2023  润新知