申明:本博客无图无真相,但是我亲测可以加载出来,假设出现只能加载一帧的情况,请在布局中加:
android:layerType="software"
下面是自定义View的代码:
package cn.zmit.foot.listviewfoot;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import java.io.InputStream;
/**
* Created by Administrator on 2016/6/15 0015.
*/
public class MyImageView extends View {
private Movie mMovie;
public MyImageView(Context context) {
super(context,null);
}
public MyImageView(Context context, AttributeSet attrs) {
super(context, attrs);
InputStream is = getResources().openRawResource(R.raw.img);
mMovie = Movie.decodeStream(is);
}
long mMovieStart = 0;
@Override
public void draw(Canvas canvas) {
long curTime = android.os.SystemClock.uptimeMillis();
if (mMovieStart == 0) {
mMovieStart = curTime;
}
if (mMovie != null) {
int duraction = mMovie.duration();
int relTime = (int) ((curTime - mMovieStart) % duraction);
mMovie.setTime(relTime);
mMovie.draw(canvas, 0, 0);
invalidate();
}
super.draw(canvas);
}
}
转载时请注明出处及相应链接,本文永久地址:https://blog.yayuanzi.com/16771.html
微信打赏
支付宝打赏
感谢您对作者kyle的打赏,我们会更加努力! 如果您想成为作者,请点我