Now I know how to draw a GIF picture in android, here is the code:
public class GIFView extends View{
private Movie movie;
private InputStream is;
private long moviestart;
public GIFView(Context context) {
super(context);
is=getResources().openRawResource(R.drawable.anim_cerca);
movie=Movie.decodeStream(is);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
long now=android.os.SystemClock.uptimeMillis();
if (moviestart == 0)
moviestart = now;
int relTime = (int)((now - moviestart) % movie.duration());
movie.setTime(relTime);
movie.draw(canvas,10,10);
this.invalidate();
}
}
At the end, there is the movie.draw(canvas,x,y)
code, where the x and y is the coordinate for the gif picture (x=left, y=top). But how could I change the width and the height of the movie? Maybe give the right and bottom coordinates, but how, where? Thank you!
i had the same problem here is my solution, add this code in ondraw method before movie.draw
canvas.scale((float)this.getWidth() / (float)movie.width(),(float)this.getHeight() / (float)movie.height());
or
canvas.scale(1.9f, 1.21f);//this changes according to screen size
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