我需要制作一个要旋转的 ImageView。为此,我使用了以下代码。
res/anim/rotator.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<rotate
android:duration="6000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="1"
android:toDegrees="359"></rotate>
</set>
Activity.class
final Animation myRotation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotator);
imgSplashLogo.startAnimation(myRotation);
图像在 mycase 中旋转。
但在旋转时卡住,而不是平滑。
我的代码可能哪里出错了。
请检查。提前致谢...
最佳答案
An interpolator defines the rate of change of an animation. This allows the basic animation effects (alpha, scale, translate, rotate) to be accelerated, decelerated, repeated ;
您需要在 rotate
部分添加 android:interpolator="@android:anim/linear_interpolator"
。
最后
<set xmlns:android="http://schemas.android.com/apk/res/android"
>
<rotate
android:duration="6000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="1"
android:toDegrees="359"
android:interpolator="@android:anim/linear_interpolator"></rotate>
</set>
您可以使用setDrawingCacheEnabled(true);
Enabling the drawing cache is similar to setting a layer when hardware acceleration is turned off.
关于android - ImageView 中的动画旋转不流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35129076/