How to show Animated GIF image in android application?

后端 未结 11 1628
臣服心动
臣服心动 2020-12-28 13:16

I want to show an animated GIF image in an android application like the image below. I have tried the webview but no success. How to show the animated gif in the application

11条回答
  •  孤独总比滥情好
    2020-12-28 13:57

    Try this way :

        Movie movie,movie1;
        InputStream is=null,is1=null;
        long moviestart;
        long moviestart1;
        public GIFView(Context context) {
            super(context);
            is=context.getResources().openRawResource(R.drawable.hxps);
            is1=context.getResources().openRawResource(R.drawable.cartoon);
            movie=Movie.decodeStream(is);
            movie1=Movie.decodeStream(is1);
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
            canvas.drawColor(0xFFCCCCCC);
            super.onDraw(canvas);
            long now=android.os.SystemClock.uptimeMillis();
            System.out.println("now="+now);
             if (moviestart == 0) {   // first time
                 moviestart = now;
    
             }
             if(moviestart1==0)
             {
                 moviestart1=now;
             }
             System.out.println("\tmoviestart="+moviestart);
             int relTime = (int)((now - moviestart) % movie.duration()) ;
             int relTime1=(int)((now - moviestart1)% movie1.duration());
             System.out.println("time="+relTime+"\treltime="+movie.duration());
             movie.setTime(relTime);
             movie1.setTime(relTime1);
             movie.draw(canvas,0,0);
             movie1.draw(canvas,10,300);
             this.invalidate();
        }
    

    enter image description here

提交回复
热议问题