3
votes
  1. I have made a set of 3 images that will represent the move of a animal. Each image represents a frame and consists only in the animal with transparent background.

  2. I have made a AnimationDrawable in code and created the animation:

    AnimationDrawable staticAnimation = new AnimationDrawable();
    staticAnimation.addFrame(ctx.getResources().getDrawable("frame1"),150);
    staticAnimation.addFrame(ctx.getResources().getDrawable("frame2"),150);
    staticAnimation.addFrame(ctx.getResources().getDrawable("frame3"),150);
  3. I set the animation as a background for a Imageview and start it

    imgAnimal.setBackgroundDrawable(staticAnimation );
    staticAnimation.start()

Because the frames have different width (the drawing needs to recreate steps move) looks like the Imageview resizes the images in the animation. Better to say, if frame1 is bigger then frame2, frame 1 is displayed ok but frame 2 is stretched to be as big as frame1 was. Looks really awful.

Any suggestions on how to stop this behavior ? Thank you.

1

1 Answers

2
votes

The solution was quite simple, because images in frames have same height but different width, I simply made a transparent border rectangle and put it over each frame. In this case each frame will have the same width and the animatin will run as supposed to.