申明:本博客无图无真相,但是我亲测可以加载出来,假设出现只能加载一帧的情况,请在布局中加:
代码如下 | 复制代码 |
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); } } |
时间: 2024-11-27 13:52:43