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組件,注冊監(jiān)聽事件,加載資源文件等2022-11-11Android小部件Widget開發(fā)過程中的坑和問題小結
這篇文章主要介紹了Android小部件Widget開發(fā)過程中的坑和問題小結,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-09