zionlion
zionlion

Reputation: 1

Android Frame animation does not proceed more than one image

I have created a folder called anim inside res folder. I have put 9 consequtive images in a folder called drawable inside res folder. Now I have created this:

public class AndroidAnimationActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about_screen);
    ImageView myAnimation = (ImageView)findViewById(R.id.myanimation);
    final AnimationDrawable myAnimationDrawable= (AnimationDrawable)myAnimation.getDrawable();
    myAnimation.post(new Runnable(){  
        public void run() {   
            myAnimationDrawable.start();  
            }
        });
    }
}

As you see I am trying to display this animation on a page called about_screen. It only shows the first frame and the rest of the frames are not shown (as animation). I have seen several people having similar problem like me but not exactly the same. I hope someone can help me with this. Please be specific. I am a new android learner. Thanks

Upvotes: 0

Views: 230

Answers (1)

Darshan
Darshan

Reputation: 2333

Even I faced this problem, and the solution is simple. The problem is, you are calling myAnimationDrawable.start() inside the onCreate() function.

You have two possible alternatives...

First one, make the animation interactive, so that you can call myAnimationDrawable.start() inside some onClick() function.

Second option is to call myAnimationDrawable.start() inside View.OnFocusChangeListener(). In this case you don't have to make it interactive.

Upvotes: 1

Related Questions