1
我試過這樣的,這是我在網上找到發揮GIF圖片:Play.gif圖像,而無需使用的WebView
private class MYGIFView extends View {
Movie movie;
InputStream is = null;
long moviestart;
public MYGIFView(Context context) {
super(context);
// Provide your own gif animation file
is = context.getResources().openRawResource(R.drawable.mygif);
movie = Movie.decodeStream(is);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.WHITE);
super.onDraw(canvas);
long now = android.os.SystemClock.uptimeMillis();
System.out.println("now=" + now);
if (moviestart == 0) { // first time
moviestart = now;
}
System.out.println("\tmoviestart=" + moviestart);
int relTime = (int) ((now - moviestart) % movie.duration());
System.out.println("time=" + relTime + "\treltime="
+ movie.duration());
movie.setTime(relTime);
movie.draw(canvas, this.getWidth()/2 - 20,
this.getHeight()/2 - 40);
this.invalidate();
}
雖然很多人說,他們得到了他們想要的結果。
我已經把gif圖像放在drawable中。 我越來越movie.duration()爲空。
請建議我在哪裏錯了,或者如果有什麼方法。