Android动画无限旋转,不停顿

标签 android android-studio animation rotation infinite

我可以无限旋转我的图像。但我的问题是图像在达到 360° 时会短暂暂停,然后再次开始旋转。即使我应用“线性插值器”,也会发生同样的情况。 我想要做的是图像在开始下一轮时根本不会暂停。所以它必须在任意角度以相同的速度无限旋转。

Here is my - code. Thanks

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
    android:interpolator="@android:anim/linear_interpolator"
    android:duration="1400"
    android:pivotX="50%"
    android:pivotY="50%"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:repeatMode="restart"
    android:repeatCount="infinite" />
</set>

How I call it on my code

    rotate= AnimationUtils.loadAnimation(context, R.anim.loop_rotate)
    binding.imgSecondLayout.startAnimation(rotate)

感谢您的帮助! :)

最佳答案

animation.setRepeatCount(Animation.INFINITE) 添加到调用动画的 Java 类中。

我的最终代码在这里给出:

Animation animation = AnimationUtils.loadAnimation(getBaseContext(), R.anim.loop_rotate);
animation.setInterpolator(new LinearInterpolator());
animation.setRepeatCount(Animation.INFINITE);
animation.setDuration(1400);
youractivity.startAnimation(animation);

关于Android动画无限旋转,不停顿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70416855/

相关文章:

android - 如何更改 EditText 上下文菜单的背景?

java - 两个用不同语言编写的应用程序可以通信吗?

java - 如何区分ApplicationContext和Context?

java - Android 资源链接在 Apk 构建上失败

ios - 动画 UICollectionView 补充 View 调整大小

android - 如何为背景图像的变化设置动画?

android - android < 3.0 中的属性动画

java - 启动 android studio 时出错

java - 不兼容的类型 : Cannot Cast View to CheckPreferenceBox

javascript - 动画变化的排名表