使用下面的代碼
public void startMoving() {
rotateAnimation1 = null;
try {
if (duration < 1500) {
rotateAnimation1 = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation1.setInterpolator(new LinearInterpolator());
rotateAnimation1.setDuration(duration);
rotateAnimation1.setRepeatCount(0);
imgBottle.startAnimation(rotateAnimation1);
flagSpinAvailable = false;
rotateAnimation1.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation anim) {
};
public void onAnimationRepeat(Animation anim) {
};
public void onAnimationEnd(Animation anim) {
duration = duration + 70;
startMoving();
};
});
} else {
duration = duration + 100;
final float degree = (float) (Math.random() * 360);
degreeBack = 360 - degree;
rotateAnimation2 = new RotateAnimation(0, degree,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation2.setInterpolator(new LinearInterpolator());
rotateAnimation2.setDuration(duration);
rotateAnimation2.setRepeatCount(0);
rotateAnimation2.setFillAfter(true);
imgBottle.startAnimation(rotateAnimation2);
rotateAnimation2.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation anim) {
};
public void onAnimationRepeat(Animation anim) {
};
public void onAnimationEnd(Animation anim) {
afterSpinEnd();
};
});
}
} catch (Exception e) {
flagSpinAvailable = true;
e.printStackTrace();
}
}
這是我的代碼自己周圍旋轉圖像,慢慢降低速度
這是正確的,我當觸摸屏幕時圖像不斷旋轉,並在觸摸事件結束時停止旋轉。 – n00bdev
我不確定這是否是正確的方式來反轉旋轉,但我向startRotating()和StopRotating()部分添加了一個'returnRotating'變量,以使針返回到原始位置,如下所示: public void stopRotating() { \t keepRotating = false; if(!returnRotating) // ... – n00bdev
嗯,你的意思是你想讓針在開始下一圈之前回到原來的位置?就像我開始,然後停止針。然後再次啓動,它應該從0開始,而不是從停止的地方繼續。正確?對於這個使用returnRotating布爾值應該沒問題。但這一切都取決於你的要求和邏輯:) –