0

I was studying the ApiDemos code samples and saw a sample which was animating a gif image. It was working fine. When I replaced that gif image i.e. R.drawable.animated_gif with my own gif image, it squashes/distorted the gif image and was not working properly. Any idea? Here is the onDraw() method of MyView class:

@Override protected void onDraw(Canvas canvas) {
            canvas.drawColor(0xFFCCCCCC);                           
            long now = android.os.SystemClock.uptimeMillis();
            if (mMovieStart == 0) {
                mMovieStart = now;
            }
            if (mMovie != null) {

                int dur = Math.max(mMovie.duration(), 1);
                int pos = (int)(now % dur);
                mMovie.setTime(pos);
                mMovie.draw(canvas, getWidth() - mMovie.width(),
                            getHeight() - mMovie.height());
                invalidate();
            }
}
Khawar Raza
  • 15,870
  • 24
  • 70
  • 127
  • http://stackoverflow.com/questions/3660209/android-display-animated-gif See if this helps ! – m4n07 Apr 17 '12 at 15:56

2 Answers2

0

Since you've proved no code, it's hard to help, however, have you tried:

android:scaledType="centerInside"

or

android:scaledType="centerCrop"

These attributes inside your ImageView?

Kyle
  • 611
  • 4
  • 6
0

Check your second gif name. You shouldn't have spaces and -,+... I have the same problem earlier and find that the name of image was causing error

lowselfesteemsucks
  • 825
  • 1
  • 13
  • 21
  • I am using the following to get image from resources; is = context.getResources().openRawResource(R.drawable.skeleton); mMovie = Movie.decodeStream(is); animation is distorted. – Khawar Raza Apr 17 '12 at 16:16
  • what is the name of gif image in drawable folder? and one think more, do you change something in your code? – lowselfesteemsucks Apr 17 '12 at 16:26
  • Yes I made changes in the code but both the original ApiDemos and modified code results in same animation distortion. – Khawar Raza Apr 17 '12 at 16:32