JRowan
JRowan

Reputation: 7104

How do you run an animation with a Image view?

im looking for an example code, my xml is fine, i want to start the animation right when the activity is started, not pressing anything

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

public class AnimationActivity extends Activity
{
ImageView genie;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
  genie = (ImageView)findViewById(R.id.genieout);
genie.setBackgroundResource(R.drawable.genieani);


genie.post(new Runnable() {
    @Override
    public void run() {
        AnimationDrawable genieout =
            (AnimationDrawable) genie.getBackground();
        genieout.start();
    }
});

}

Upvotes: 0

Views: 312

Answers (2)

Robert Estivill
Robert Estivill

Reputation: 12477

Take a look to NineOldAndroids. Is a very good library that backports HoneyComb+ animations back to android 1.0.

http://nineoldandroids.com/

Pretty sure you will find what you need in the library examples source code here

https://github.com/JakeWharton/NineOldAndroids/tree/master/sample

Upvotes: 0

Snicolas
Snicolas

Reputation: 38168

public void onStart() {
   super.onStart();
   myImageView.startAnimation( myAnimation );
}

Upvotes: 1

Related Questions