Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android播放gif格式圖片示例

android播放gif格式圖片示例

編輯:關於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);

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved