Introduction to the 1.Movie class
2. Code implementation
Importandroid.app.Activity;ImportAndroid.content.Context;ImportAndroid.graphics.Canvas;ImportAndroid.graphics.Movie;ImportAndroid.graphics.Paint;ImportAndroid.os.Bundle;ImportAndroid.util.AttributeSet;ImportAndroid.view.View; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (NewMygifview ( This)); } classMygifviewextendsview{//Movie managing multiple frames in a GIF picture Privatemovie Movie; //indicates the absolute time to start playing a GIF picture Private LongMoviestart; PublicMygifview (Context context, AttributeSet attrs) {Super(context, attrs); } PublicMygifview (Context context) {Super(context); Movie=Movie.decodestream (Getresources (). Openrawresource (R.DRAWABLE.MAIDI3)); } @Overrideprotected voidOnDraw (canvas canvas) {Super. OnDraw (canvas); LongCurrentTime =Android.os.SystemClock.uptimeMillis (); //first time playback if(Moviestart = = 0) {Moviestart=currenttime; } //Loop Playback if(Movie! =NULL){ intDuration =movie.duration (); intReltime = (int) ((Currenttime-moviestart)%duration); Movie.settime (Reltime); Movie.draw (Canvas,10,20);//Paint paint = new paint ();//Paint.setcolor (Getresources (). GetColor (Android. R.color.holo_green_light));//Movie.draw (canvas,10,20, paint);invalidate (); } } } }
The Movie class in Android displays GIF pictures