亲宝软件园·资讯

展开

android播放gif格式图片 android播放gif格式图片示例

人气:0
想了解android播放gif格式图片示例的相关内容吗,在本文为您仔细讲解android播放gif格式图片的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:播放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);

加载全部内容

相关教程
猜你喜欢
用户评论