Transforming DrawableAnimation Android

Today I added a flash screen to MultiMaze. On the screen I wanted to have a MultiMaze “player” run across the screen. This is how I achieved it:

// Animate the players fluttering cape
ImageView playerImageView = (ImageView)this.findViewById(R.id.player);
AnimationDrawable playerFlutterAnimation = new AnimationDrawable();
Drawable p1 = this.getResources().getDrawable(R.drawable.player_1);
Drawable p2 = this.getResources().getDrawable(R.drawable.player_2);
playerFlutterAnimation.addFrame(p1, 200);
playerFlutterAnimation.addFrame(p2, 200);
playerFlutterAnimation.setOneShot(false);
playerImageView.setImageDrawable(playerFlutterAnimation);
playerFlutterAnimation.start();

// Animate player movement from left to right
ObjectAnimator playerMoveAnimation = 
   ObjectAnimator.ofFloat(playerImageView, "translationX", -100f, 1000f);
playerMoveAnimation.setDuration(3000);
playerMoveAnimation.start();

The result:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>