我想在android上连续循环旋转imageview。我的代码旋转在没有设置重复模式的情况下工作得很好。如果我设置重复模式重复动画不起作用但是,imageview静态旋转一些角度,我想要循环旋转动画任何人都可以帮助我非常感谢!
这是动画xml
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="50%"
android:pivotY="50%"
android:duration="100"
android:startOffset="0"
/>
这是我的java类
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class AnimationActivity extends Activity {
/** Called when the activity is first created. */
ImageView my_image;
AnimationListener listener;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listener = new AnimationListener() {
@Override public void onAnimationStart(Animation animation) {}
@Override public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
System.out.println("End Animation!");
//load_animations();
}
};
my_image=(ImageView)findViewById(R.id.my_img);
load_animations();
}
void load_animations()
{
new AnimationUtils();
Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotation);
rotation.setRepeatCount(-1);
rotation.setRepeatMode(2);
rotation.setAnimationListener(listener);
my_image.startAnimation(rotation);
}
}
提前致谢!