public class MyGifView extends View {
private Movie movie;
private long movieStart;
public MyGifView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
movie = Movie.decodeStream(getResources().openRawResource(R.drawable.a));
}
//重写绘制方法
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
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);
}
private Movie movie;
private long movieStart;
public MyGifView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
movie = Movie.decodeStream(getResources().openRawResource(R.drawable.a));
}
//重写绘制方法
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
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);
}