android播放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);
相关文章
android自动安装apk代码实例(不使用apk安装器安装)
这篇文章主要介绍了android自动安装apk代码实例,代码简单,大家参考使用吧2013-11-11
Android中Gallery和ImageSwitcher的使用实例
今天小编就为大家分享一篇关于Android中Gallery和ImageSwitcher的使用实例,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧2019-03-03
刷新Activity中的scrollview示例(局部ui刷新)
代码很简单,但是很实用,适合在一个Activity中要刷新局部的UI,比如在扫描一维码的时候,要把每次扫描的结果都显示在界面上2014-01-01


最新评论