android播放gif格式图片示例
import android.content.context;
import android.graphics.canvas;
import android.graphics.movie;
import android.util.attributeset;
import android.view.view;
import android.view.viewgroup.layoutparams;
import com.nmbs.r;
public class gifview extends view {
private long moviestart;
private movie movie;
public gifview(context context, attributeset attributeset) {
super(context, attributeset);
movie = movie.decodestream(getresources().openrawresource(
r.drawable.ic_showseat));
}
public gifview(context context) {
super(context);
movie = movie.decodestream(getresources().openrawresource(
r.drawable.ic_showseat));
}
@override
protected void ondraw(canvas canvas) {
long curtime = android.os.systemclock.uptimemillis();
if (moviestart == 0) {
moviestart = curtime;
}
if (movie != null) {
int duraction = movie.duration();
int reltime = (int) ((curtime - moviestart) % duraction);
movie.settime(reltime);
movie.draw(canvas, 0, 0);
invalidate();
}
super.ondraw(canvas);
}
@override
public void setlayoutparams(layoutparams params) {
super.setlayoutparams(params);
}
}
gifview gifview = new gifview(this);