0

我在 android 中使用动画视图来显示 gif 文件。它在姜饼上运行良好,但在 ICS 上不运行。我应该怎么做才能在android上运行它?我指的是以下代码:-

public class AnimationView extends View {
private Movie mMovie;
private long mMovieStart;
private static final boolean DECODE_STREAM = true;
private static byte[] streamToBytes(InputStream is) {
  ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
  byte[] buffer = new byte[1024];
  int len;
  try {
    while ((len = is.read(buffer)) >= 0) {
      os.write(buffer, 0, len);
    }
  } catch (java.io.IOException e) {
  }
  return os.toByteArray();
}

 public AnimationView(Context context,AttributeSet attrs) {
  super(context,attrs);
  setFocusable(true);

  java.io.InputStream is;
  is = context.getResources().openRawResource(R.drawable.applogo);
  if (DECODE_STREAM) {
    mMovie = Movie.decodeStream(is);
  } else {
    byte[] array = streamToBytes(is);
    mMovie = Movie.decodeByteArray(array, 0, array.length);
  }
}
@Override
public void onDraw(Canvas canvas) {
 long now = android.os.SystemClock.uptimeMillis();
  if (mMovieStart == 0) { // first time
    mMovieStart = now;
  }
  if (mMovie != null) {
    int dur = mMovie.duration();
    if (dur == 0) {
      dur = 3000;
    }
    int relTime = (int) ((now - mMovieStart) % dur);
   Log.d("", "real time :: " +relTime);
    mMovie.setTime(relTime);
    mMovie.draw(canvas, getWidth()-300, getHeight()-375);
    invalidate();
  }
}

}

请提出一些建议。.

4

0 回答 0