Я пытаюсь показать две разные анимации. Работает нормально с первым. Но когда я останавливаю первую анимацию и вызываю setBackgroundResource () второй раз со своей второй анимацией (а затем вызываю start ()), он показывает только первый кадр.
Можно ли вызвать setBackgroundResource () дважды, чтобы установить разные анимации?
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
ImageView imgView= (ImageView) findViewById(R.id.imgView);
imgView.setBackgroundResource(R.anim.animation1);
AnimationDrawable frameAnimation = (AnimationDrawable) imgView
.getBackground();
frameAnimation.setCallback(imgView);
frameAnimation.start();
//Schedule the timer
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
showAnimation2();
}
}, 20000);
}//if hasFocus
}
/**
* Show second animation
*/
public void showAnimation2(){
ImageView imgView= (ImageView) findViewById(R.id.imgView);
AnimationDrawable frameAnimation = (AnimationDrawable) imgView
.getBackground();
// stop first animation
frameAnimation.stop();
imgView.setBackgroundResource(R.anim.animation2);
frameAnimation.setCallback(imgView);
//start second animation
frameAnimation.start();
// here I see the first frame of second animation only
}
Я также пытался поиграть с setVisible (...), но это не помогло