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 ApplicationContext接口深入分析
ApplicationContext是Spring应用程序中的中央接口,由于继承了多个组件,使得ApplicationContext拥有了许多Spring的核心功能,如获取bean组件,注册监听事件,加载资源文件等2022-11-11
最新评论