Android 旋转图像视图卡住

Android 旋转图像视图卡住,android,imageview,rotateanimation,Android,Imageview,Rotateanimation,我想创建一个简单的图像,它可以旋转20度(像时钟一样)并向后旋转20度。我有一个简单的布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"

我想创建一个简单的图像,它可以旋转20度(像时钟一样)并向后旋转20度。我有一个简单的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/witewall_3">

    <ImageView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:id="@+id/pet"
        android:src="@drawable/animal"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>
我做错了什么,我的图像没有旋转?
我已经尝试了很多教程,但没有任何效果:(

您正在从0旋转到0度。第一个参数是from degrees,RotationAnimation类的第二个参数是ending point degrees

RotateAnimation anim = new RotateAnimation(0f, 20f, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
如果要继续旋转二十度,还需要提供第一个参数,即它将设置动画的角度

RotateAnimation anim = new RotateAnimation(20f, 40f, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
RotateAnimation anim = new RotateAnimation(40f, 60f, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);

虽然这个代码只有答案可以解决目前的问题,更多的解释是必要的,以帮助网站的未来用户了解如何应用这个解决方案,以他们的情况。请考虑添加到您的答案。
RotateAnimation anim = new RotateAnimation(20f, 40f, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
RotateAnimation anim = new RotateAnimation(40f, 60f, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
set degree from 0 to 360 when you define RatateAnimation()

RotateAnimation rotateAnimation = new RotateAnimation(0, 360);
rotateAnimation.setDuration(5000);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setRepeatMode(Animation.INFINITE);
image.setAnimation(rotateAnimation);