我正在做动态壁纸。我有一个Runnable
(每 5 秒更新一次),我在其中调用一个draw()
在Canvas
. 它调用另一个类中的一个方法,该方法应该绘制一系列位图(有延迟,所以它是动画的)。我将如何更改下面的代码,以便延迟绘制下一个位图?
int imageToDraw = 10;
while(imageToDraw>=0)
{
Bitmap b = BitmapFactory.decodeResource(mContext.getResources(), mContext.getResources().getIdentifier("image_"+imageToDraw, "raw", mContext.getPackageName()));
float centerX = (width - b.getWidth())/2;
float centerY = (height - b.getHeight())/2;
Paint p = new Paint();
p.setColor(Color.BLACK);
mCanvas.drawRect(0f, 0f, (float)width, (float)height, p); //draws a rectangle to clear the screen
mCanvas.drawBitmap(b, centerX, centerY, new Paint());
--imageToDraw;
b.recycle();
}