How to play animated GIF image from url in android?

后端 未结 4 1105
梦谈多话
梦谈多话 2021-01-16 12:17

I am integrating giphy to my android app..

How can i play animated gif image from URL in android? Should I use ImageView, WebView, VideoView

4条回答
  •  星月不相逢
    2021-01-16 12:51

    Try this way

        Movie movie;
        GifView(Context context) {
            super(context);
            movie = Movie.decodeStream(
                    context.getResources().openRawResource(
                            R.drawable.some_gif));
        }
        @Override
        protected void onDraw(Canvas canvas) {   
            if (movie != null) {
                movie.setTime(
                    (int) SystemClock.uptimeMillis() % movie.duration());
                movie.draw(canvas, 0, 0);
                invalidate();
            }
        }
    

提交回复
热议问题