我是新手 Android 开发者。我在编写一个旨在暂停应用程序直到动画结束的方法时遇到了问题。
这是我的代码:
public void CorrectAnimation() {
Log.d("CorrectAnim", "Pass" );
final Button answer_1 = (Button) findViewById(R.id.answer_1);
final Button answer_2 = (Button) findViewById(R.id.answer_2);
final Button answer_3 = (Button) findViewById(R.id.answer_3);
final Button answer_4 = (Button) findViewById(R.id.answer_4);
if (iAnswer_1 == 1) {
answer_1.setBackgroundResource(R.drawable.button_correctly);
AnimationDrawable animAnswer_1 = (AnimationDrawable) answer_1.getBackground();
animAnswer_1.start();
checkIfAnimationDone(animAnswer_1);
}
...
}
private void checkIfAnimationDone(AnimationDrawable anim){
Log.d("Check", "Pass" );
final AnimationDrawable a = anim;
int timeBetweenChecks = 2500;
Handler h = new Handler();
h.postDelayed(new Runnable(){
@override
public void run(){
Log.d("checkRun", "Pass" );
if (a.getCurrent() != a.getFrame(a.getNumberOfFrames() - 1)){
Log.d("checkRunIf", "Pass" );
checkIfAnimationDone(a);
} else{
Toast.makeText(getApplicationContext(), "ANIMATION DONE!", Toast.LENGTH_SHORT).show();
}
}
}, timeBetweenChecks);
};
问题是checkIfAnimationDone()
忽略了方法Run()
。
解决:我忘记在上面添加@override" public run()"。代码现在正在运行:)
答案 0 :(得分:0)
看看这个问题,他正在使用onAnimationFinished()方法进行重写......