Alex Rivera | Logout

AnimationDrawable not playing

Asked 2011-03-30T18:52:23.860
23

So I want my animation to start as soon as the activity is created, but for some reason no matter what I try will get it to start. I can get it to start by having a click event but I want it to start all on its own.

Here's what I have and how do I get this to work?

package tween.learn;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;

public class Animate extends Activity {

    public ImageView image;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        ImageView tweenImage = (ImageView) findViewById(R.id.imageView1);
        tweenImage.setBackgroundResource(R.anim.cubicfacetween);

        AnimationDrawable frameAnimation = 
                           (AnimationDrawable) tweenImage.getBackground();
        frameAnimation.start();

        }



}

Thanks

Edit
Report

1 Answer

3

Try starting your animation after the window gets focus by overriding onWindowFocusChanged in your Activity:

  @Override
  public void onWindowFocusChanged (boolean hasFocus)
  {
      //Start animation here
  }

See docs here: http://developer.android.com/reference/android/app/Activity.html#onWindowFocusChanged%28boolean%29

answered 2011-03-30T19:00:54.717

Your Answer