时间:2021-09-17 09:39:09 | 栏目:Android代码 | 点击:次
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);
}
}