android - 连续旋转图像

标签 android animation rotation

我有以下代码尝试连续旋转图像:

Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_animation); image.startAnimation(animation);

rotate_animation.xml文件如下:

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

上述代码的问题在于它旋转图像并在再次旋转之前暂停。我正在寻找的是平滑的连续旋转,只有在我明确需要它停止时才会停止。

最佳答案

转到属性动画师,这是现在推荐的动画方法。试试这个-

ImageView imageview = (ImageView)findViewById(R.id.yourimage);

ObjectAnimator imageViewObjectAnimator = ObjectAnimator.ofFloat(imageview ,
                    "rotation", 0f, 360f);
imageViewObjectAnimator.setRepeatCount(ObjectAnimator.INFINITE);
imageViewObjectAnimator.setRepeatMode(ObjectAnimator.RESTART);
imageViewObjectAnimator.setInterpolator(new AccelerateInterpolator());
imageViewObjectAnimator.start();

关于android - 连续旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37053757/

相关文章:

javascript - Android App软键盘覆盖嵌入webview的网页textarea

android - 在 Android 上使用哪种网络服务技术?

javascript - D3.js - 补间弧位置,内半径和外半径 - D3.js Arc

python - 如何改变 turtle 旋转的速度?

ios - 使用 Xcode Storyboards 实现丰富的旋转 UI

android - 如何在自己的应用程序中集成谷歌手写输入键盘?

android - Datepicker 不应受 android 中主题的影响

css - 为什么这个 CSS3 旋转动画设置在 Chrome 和 Safari 上不起作用?

ios - 停止特定的 UIView 动画 block - iOS

iOS8 Modal ViewController 旋转问题