首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 平面设计 > 图形图像 >

展示gif图像用系统movie类

2012-08-31 
显示gif图像用系统movie类import android.app.Activityimport android.content.Contextimport android.g

显示gif图像用系统movie类
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.os.Bundle;
import android.view.View;

public class demo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}

private static class SampleView extends View {
private Movie mMovie;
private long mMovieStart;

public SampleView(Context context) {
super(context);
setFocusable(true);
InputStream is;
is = context.getResources()
.openRawResource(R.drawable.jj);
mMovie = Movie.decodeStream(is);
}
@Override
protected void onDraw(Canvas canvas) {

long now = android.os.SystemClock.uptimeMillis();
if (mMovieStart == 0) { // first time
mMovieStart = now;
}
if (mMovie != null) {
int dur = mMovie.duration();
if (dur == 0) {
dur = 1000;
}
int relTime = (int) ((now - mMovieStart) % dur);
mMovie.setTime(relTime);
mMovie.draw(canvas, 20, 100);
invalidate();
}
}
}
}

热点排行