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
I think you have to start the animation after initialization of the view in question is complete. You should be able to do something like:
final ImageView tweenImage = (ImageView) findViewById(R.id.imageView1); tweenImage.setBackgroundResource(R.anim.cubicfacetween); tweenImage.post(new Runnable() { @Override public void run() { AnimationDrawable frameAnimation = (AnimationDrawable) tweenImage.getBackground(); frameAnimation.start(); } }
Edit - this question led me to believe that the onWindowFocusChanged
method won't always work. It does seem simpler and is probably a better idea if it works for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With