我使用Android动画来旋转图像视图,但移动非常不平稳

我使用Android动画来旋转图像视图,但移动非常不平稳,android,animation,graphics,Android,Animation,Graphics,这是我的XML动画 <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" androi

这是我的XML动画

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


我将其应用于ImageView,作为旋转图像的一种方法。但这场运动非常动荡。每次图像旋转时,它似乎会在旋转过程中的两个彼此相差180度的点处跳过。我看不出发生这种情况的原因,是否有人遇到这种困难并找到了解决方法?

尝试设置不同的插值器。仅供参考,在android中创建动画时使用的默认插值器不是线性插值器,而是
加速加速插值器

我不知道为什么没有得到正确的结果。这对我有用

可以使用动画XML文件中的内置android.R.anim.linear_插值器

android:interpolator="@android:anim/linear_interpolator".
或者,您可以在项目中创建自己的XML插值文件,例如,命名它

res/anim/linear_interpolator.xml:

<?xml version="1.0" encoding="utf-8"?>
<linearInterpolator xmlns:android="http://schemas.android.com/apk/res/android" />
和使用

android:toDegrees="360" 


由于360度和0度是相同的

请尝试此操作,使xml文件成为可绘制文件,并将可绘制代码放在下面,将此文件命名为my_progress_undeterminate.xml:

<?xml version="1.0" encoding="utf-8"?><animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/your_rotating_image"
android:pivotX="50%"
android:pivotY="50%" />

很抱歉,但您必须将其放在进度栏中,就像这样很简单,如果图像是静态的,则与图像视图相同,不需要为此执行任何不同的编码,只需在布局xml文件中这样编写:

 <ProgressBar android:indeterminateDrawable="@drawable/my_progress_indeterminate" android:layout_height="100dp" android:layout_width="100dp"></ProgressBar>


模拟器总是不稳定的。尝试在设备中调试它。如果不是的话,加快旋转速度。

如果这个旋转非常重要,我想它是UI中非常重要的一部分

在这种情况下,您应该对简单的OpenGL实现感兴趣,它将帮助您解决问题

我建议使用-简单且易于实现


在上面你可以找到很好的代码样本,甚至太多了

尝试从0度到359度。您是在模拟器中还是在真实设备上进行尝试?在中高端设备上应该是平滑的。当我尝试在我的一个项目中使用你的动画时,这里没有任何问题。运行Android 3.2的Galaxy Tab 10.1。您是否尝试过启用硬件加速?这让我的动画更加流畅。可能的复制我需要一个平滑的线性旋转。我正在制作一个转动的轮子的动画,你是否可以将旋转效果与其他效果一起应用?(例如移动效果或其他什么?因为这肯定是个问题)。不,ImageView是静态的,由标准XML布局设置。图像源以相同的标准方式完成。这是我对它应用的唯一效果。如果您需要一个imageview,或者只需要一个动画id在视图上运行,该怎么办?
<?xml version="1.0" encoding="utf-8"?><animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/your_rotating_image"
android:pivotX="50%"
android:pivotY="50%" />
 <ProgressBar android:indeterminateDrawable="@drawable/my_progress_indeterminate" android:layout_height="100dp" android:layout_width="100dp"></ProgressBar>