zoukankan      html  css  js  c++  java
  • android gif播放

    package com.ttw.gif;


    import java.io.IOException;
    import java.io.InputStream;


    import com.ttw.androidhtppclient.Utility;


    import android.content.Context;
    import android.graphics.BitmapFactory;
    import android.graphics.Canvas;
    import android.graphics.Movie;
    import android.util.AttributeSet;
    import android.view.View;
    import android.view.ViewGroup.LayoutParams;


    public class GifMove extends View {


    private Movie mMovie;


    private InputStream is = null;

    private long mMovieStart;


    public GifMove(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    }


    public GifMove(Context context, AttributeSet attrs) {
    super(context, attrs);
    }


    public GifMove(Context context) {
    super(context);
    }


    public void setGifSource(int source) {

    BitmapFactory.Options option = new BitmapFactory.Options();
    option.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(getResources(), source, option);
    Utility.logI("move widht = " + option.outWidth + " height = " + option.outHeight);
    LayoutParams lp = this.getLayoutParams();
    lp.width = option.outWidth;
    lp.height = option.outHeight;
    this.setLayoutParams(lp);
    if(null != is){
    try {
    is.close();
    } catch (IOException e) {
    e.printStackTrace();
    }finally{
    is = null;
    }
    }
    is = getResources().openRawResource(source);
    mMovie = Movie.decodeStream(is);
    }


    @Override
    protected void onDraw(Canvas canvas) {
    long now = android.os.SystemClock.uptimeMillis();
     
             if (mMovieStart == 0) {
                 mMovieStart = now;
             }

    if (mMovie != null) {
    int dur = mMovie.duration();
    if (dur == 0) {
    dur = 500;
    }
    int relTime = (int) ((now - mMovieStart) % dur);
    mMovie.setTime(relTime);
    mMovie.draw(canvas, getWidth() - mMovie.width(), getHeight()
    - mMovie.height());
    invalidate();
    }
    super.onDraw(canvas);
    }


    }

  • 相关阅读:
    shell编程:for循环结构
    shell编程:实现shell字符串连接功能
    jq 出现 $.cookie is not a function
    jq页面换肤效果
    js ==与===区别(两个等号与三个等号)
    JS与Jquery的事件委托机制
    jq选项卡切换功能
    licecap图片区域问题
    jquery网页定位导航特效
    ps-手捧城堡滴水云雾图
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/2988797.html
Copyright © 2011-2022 走看看