GifMovieView.java
public class GifMovieView extends View
{
private Movie mMovie;
private InputStream mStream;
public GifMovieView(Context context, InputStream stream)
{
super(context);
mStream = stream;
mMovie = Movie.decodeStream(mStream);
}
private long mMoviestart;
@Override
protected void onDraw(Canvas canvas)
{
canvas.drawColor(Color.TRANSPARENT);
super.onDraw(canvas);
final long now = SystemClock.uptimeMillis();
if (mMoviestart == 0)
{
mMoviestart = now;
}
final int relTime = (int)((now - mMoviestart) % mMovie.duration());
mMovie.setTime(relTime);
mMovie.draw(canvas, 10, 10);
this.invalidate();
}
}
Activitiy
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
InputStream stream = null;
try {
stream = getAssets().open("splash.gif");
} catch (IOException e)
{ e.printStackTrace(); }
GifMovieView view = new GifMovieView(this, stream);
setContentView(view);
}
我试图在一个Android应用程序中支持Gif图像作为我的启动画面。使用GifMovieView我也能够支持它但是有一个小缺陷即图像是动画但它不覆盖整个屏幕。请帮助!