这是单击按钮时旋转图像的java代码。图像旋转它是完美的,但如果我在旋转未结束时再次单击按钮,动画会重新启动,而不是结束动画。如何等待动画结束?我找到了 Animation.AnimationListener,我认为 onAnimationEnd 对我很有用,但我无法将它集成到我的代码中......请帮助我:-)
package com.example.helloword;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class Rotation_test extends Activity {
private float statdegree = (float) 0.0;
private float enddegree = (float) 90.0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rotation_test);
// ---------------------------------------------------------------------------------------------
Button buttonRotateCenter = (Button) findViewById(R.id.rotatecenter);
final ImageView floatingImage = (ImageView) findViewById(R.id.floatingimage);
// AnimationRotation
final Animation animationRotateCenter = new RotateAnimation(statdegree,
enddegree, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
animationRotateCenter.setDuration(5000L);
animationRotateCenter
.setInterpolator(new AccelerateDecelerateInterpolator());
// \AnimationRotation
buttonRotateCenter.setOnClickListener(new Button.OnClickListener() {
public void onClick(View arg0) {
floatingImage.startAnimation(animationRotateCenter);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_rotation_test, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}