抱歉我的英语不太好,希望你能理解我。
我的朋友是一位非常擅长画画的人。我想通过制作他的绘画成为动态壁纸来帮助他成为一名出色的画家。
我希望他能画几个帧,并使用这些帧制作一个动态壁纸,依次展示每一帧。
我很难做到显示一张图片,等待一段时间再显示下一张。我相当确定我做不到,因为我没有使用正确的方法...
以下是我迄今为止所做的:
public class Cercle extends WallpaperService
{
public void onCreate()
{
super.onCreate();
}
public void onDestroy()
{
super.onDestroy();
}
public Engine onCreateEngine()
{
return new CercleEngine();
}
class CercleEngine extends Engine
{
public Bitmap image1, image2, image3;
CercleEngine()
{
image1 = BitmapFactory.decodeResource(getResources(), R.drawable.img1);
image2 = BitmapFactory.decodeResource(getResources(), R.drawable.img2);
image3 = BitmapFactory.decodeResource(getResources(), R.drawable.img3);
}
public void onCreate(SurfaceHolder surfaceHolder)
{
super.onCreate(surfaceHolder);
}
public void onOffsetsChanged(float xOffset, float yOffset, float xStep, float yStep, int xPixels, int yPixels)
{
drawFrame();
}
void drawFrame()
{
final SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
try
{
c = holder.lockCanvas();
if (c != null)
{
c.drawBitmap(image1, 0, 0, null);
c.drawBitmap(image2, 0, 0, null);
c.drawBitmap(image3, 0, 0, null);
}
} finally
{
if (c != null) holder.unlockCanvasAndPost(c);
}
}
}
}
这段代码显示图片过快,因为我不知道如何在显示图片时等待时间…有人能给我一些提示或者展示另一种解决方案的例子吗?非常感谢!更新:通过添加Runnable来解决了我的问题:
private final Runnable drawRunner = new Runnable()
{
@Override
public void run() {
drawFrame();
}
};
然后通过添加:<\p>
handler.removeCallbacks(drawRunner);
if (visible)
{
handler.postDelayed(drawRunner, 1000); // delay 1 sec
}
在drawFrame()的末尾。
希望这能对某些人有所帮助。