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()为空。
请建议我在哪里错了,或者如果有什么方法。