Tôi sử dụng phương pháp này để bắt đầu mọi hoạt ảnh (resID của XML hoạt ảnh). Nếu nextPuzzleOnEnd là đúng, phương thức "nextPuzzle" được gọi khi hoạt ảnh kết thúc.
Phương pháp này là một phần của ứng dụng trò chơi của tôi và tôi sử dụng nó để hiển thị mọi hoạt ảnh thành công và sau đó (sau khi hoạt ảnh đã kết thúc) tiếp tục với câu đố tiếp theo.
/*
* start animation (any view)
*/
private void startAnimation(View v, int resId, Boolean nextPuzzleOnEnd){
Animation anim;
if(v!=null){ // can be null, after change of orientation
anim = AnimationUtils.loadAnimation(this.getContext(),resId);
anim.setFillAfter(false);
v.setAnimation(anim);
if(nextPuzzleOnEnd){
anim.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation anim)
{
};
public void onAnimationRepeat(Animation anim)
{
};
public void onAnimationEnd(Animation anim)
{
nextPuzzle();
};
});
}
v.startAnimation(anim);
}
}
Nguồn
2011-04-27 20:37:41