Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Gif is basically a set of images with a constant time delay in frames. You can not directly play gif in android. I've worked lot on playing gif animation in android.</p> <ul> <li><p>When playing gif we also handle all calls of playing frames by our self. So this is not a best approach</p></li> <li><p>If you have set of images just play them by a delay in frames. That would be the all you want.</p></li> <li><p>You can not make gif in application by native code as well. There are some drawbacks as well for using gif format. Which I had faced in my game.</p></li> <li><p>If you have set of drawables you can use <a href="http://developer.android.com/guide/topics/graphics/drawable-animation.html" rel="nofollow">AnimationDrawable</a> for showing aanimation like gif as well. It can also set the any View.</p></li> </ul> <p>I had also made a custom view to play gif animations. <strong>First I load gif and convert it into InputStream then I pass it to my custom view class to play the gif.</strong></p> <pre><code> public class GifWebView extends View { private Movie mMovie; InputStream mStream; long mMoviestart; private boolean play; public GifWebView(Context context, InputStream stream) { super(context); mStream = stream; setPlay(true); mMovie = Movie.decodeStream(mStream); } @Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.TRANSPARENT); super.onDraw(canvas); final long now = SystemClock.uptimeMillis(); if (mMoviestart == 0) { mMoviestart = now; } final int relTime = (int) ((now - mMoviestart) % mMovie.duration()); mMovie.setTime(relTime); mMovie.draw(canvas, 20, 20); if (play) { Log.i("reltime", "" + relTime + ",duration:" + mMovie.duration()); this.invalidate(); } } @Override public boolean onTouchEvent(android.view.MotionEvent event) { return true; }; public boolean isPlay() { return play; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload