I want to display animated GIF images in my application. As I found out the hard way Android doesn’t support animated GIF naively.
Code:
package com.sandipkalola.animatedgif;
import android.os.Bundle;
import android.os.SystemClock;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.view.View;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(new AnimatedGif(this));
}
static class AnimatedGif extends View
{
Movie movie;
AnimatedGif(Context context)
{
super(context);
movie = Movie.decodeStream(context.getResources().openRawResource( R.drawable.ball));
}
@Override
protected void onDraw(Canvas canvas)
{
if (movie != null)
{
movie.setTime((int) SystemClock.uptimeMillis() %…
View original post 40 more words
you replace “package com.sandipkalola.animatedgif;” with your package name..
Thank you, but I left everything as it was intentionally, so that all the credits go to you.