@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
new Thread(this).start();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
mLoop=false;
}
private void draw()
{
Canvas canvas=mSurfaceHolder.lockCanvas();
if(mSurfaceHolder==null||canvas==null)
{
return;
}
if(index<Image.length-1)
{
index++;
}
else
{
index=0;
}
//Paint mPaint=new Paint();
//mPaint.setAntiAlias(true);
///mPaint.setColor(Color.BLACK);
//canvas.drawRect(0,0,320,480, mPaint);
canvas.drawBitmap(((BitmapDrawable)this.getResources().getDrawable(Image[index])).getBitmap(), 0,0,null);
mSurfaceHolder.unlockCanvasAndPost(canvas);
}
@Override
public void run() {
// TODO Auto-generated method stub
while(mLoop)
{
try
{
Thread.sleep(200);
}
catch(Exception e)
{
}
synchronized (mSurfaceHolder) {
draw();
}
}
}
}
这里只是简单的记录使用方法。Android的API实在太多了。