G
G
gflower2011-11-07 15:45:39
Android
gflower, 2011-11-07 15:45:39

Changing one to another frame-by-frame animation in Android?

There was a problem showing the second animation in the same ImageView.
The first animation is shown without problems. And the second, substituted into the same ImageView, shows only the first frame. The question arises: is it possible to change animations at all, and if so, how to do it correctly?
Example of unsuccessful code:

public void onWindowFocusChanged(boolean hasFocus) {<br/>
<br/>
super.onWindowFocusChanged(hasFocus);<br/>
<br/>
if (hasFocus) {<br/>
<br/>
ImageView imgView= (ImageView) findViewById(R.id.imgView);<br/>
<br/>
// первая анимация<br/>
<br/>
imgView.setBackgroundResource(R.anim.animation1);<br/>
 AnimationDrawable frameAnimation = (AnimationDrawable) imgView<br/>
 .getBackground();<br/>
<br/>
frameAnimation.setCallback(imgView);<br/>
 frameAnimation.start();<br/>
<br/>
//Schedule the timer<br/>
<br/>
Timer timer = new Timer();<br/>
 timer.schedule(new TimerTask() {<br/>
<br/>
@Override<br/>
 public void run() {<br/>
 // показываем вторую<br/>
 showAnimation2();<br/>
 }<br/>
 }, 20000);<br/>
 }//if hasFocus<br/>
<br/>
}<br/>
<br/>
/**<br/>
 * Вторая анимация<br/>
 */ <br/>
public void showAnimation2(){<br/>
 ImageView imgView= (ImageView) findViewById(R.id.imgView);<br/>
<br/>
AnimationDrawable frameAnimation = (AnimationDrawable) imgView<br/>
 .getBackground();<br/>
<br/>
// stop first animation<br/>
 frameAnimation.stop();<br/>
<br/>
imgView.setBackgroundResource(R.anim.animation2);<br/>
 frameAnimation.setCallback(imgView);<br/>
<br/>
//start second animation<br/>
 frameAnimation.start();<br/>
<br/>
// here I see the first frame of second animation only<br/>
}<br/>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gflower, 2012-03-12
@gflower

I answer myself. The solution is this: we make two animations. We show the first, and hide the second. After the end of the first animation, make it invisible and show the second one.
But in the end, to display graphics, I switched to AndEngine. There were no problems with animated sprites.

G
gflower, 2011-11-08
@gflower

Where are you, Android Guru?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question