我有一个ImageButton
在点击时旋转的android。问题是当用户点击它并继续到下一行的新活动时,它没有完成旋转。我已经尝试过Thread.sleep(..)
,wait(..)
但RotateAnimation(..)
实际上在动画开始之前就睡着了。
我需要动画真正完成,然后继续startActivity(new Intent(..))
这是代码
amazingPicsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
amazingPicsSound = createRandButSound();
amazingPicsSound.start();
rotateAnimation(v);
startActivity(new Intent("com.jasfiddle.AmazingInterface.AMAZINGPICS"));
}
});
}
/** function that produces rotation animation on the View v.
* Could be applied to button, ImageView, ImageButton, etc.
*/
public void rotateAnimation(View v){
// Create an animation instance
Animation an = new RotateAnimation(30, 360, v.getWidth()/2, v.getHeight()/2);
// Set the animation's parameters
an.setDuration(20); // duration in ms
an.setRepeatCount(10); // -1 = infinite repeated
// an.setRepeatMode(Animation.REVERSE); // reverses each repeat
an.setFillAfter(true); // keep rotation after animation
v.setAnimation(an);
// Apply animation to the View
}