欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

android播放gif格式图片示例

程序员文章站 2023-11-14 08:34:10
复制代码 代码如下:import android.content.context;import android.graphics.canvas;import android...

复制代码 代码如下:

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);