(對不起,我的英語不太好...希望你能理解我)動態壁紙與圖像
我的朋友是一個非常好的抽屜。我想幫助他通過使他成爲一個動畫與他的圖紙動態壁紙知道作爲一個很好的抽屜。
我想讓他畫幾幀,並使用這些幀來製作一個接一個地顯示它們的動態壁紙。
我很努力地顯示一張圖片,然後等待一下,然後顯示下一張圖片。我敢肯定,我不能成功做到這一點,因爲我不使用正確的方法...
這是我到現在爲止完成:
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);
}
}
}
}
此代碼只是顯示圖片太快,因爲我不知道如何等待圖片之間的間隔...
任何人都可以給我一些提示或給我看一些另一種解決方案的例子嗎?
非常感謝!
UPDATE:
我得到了我的問題,通過增加一個Runnable解決:
private final Runnable drawRunner = new Runnable()
{
@Override
public void run() {
drawFrame();
}
};
,然後通過添加:
handler.removeCallbacks(drawRunner);
if (visible)
{
handler.postDelayed(drawRunner, 1000); // delay 1 sec
}
在並條機的結束()。
希望這會幫助別人。
謝謝艾哈邁德!我通過查看鏈接中的源代碼來解決問題。對不起,我想給你投票,但它告訴我,我需要15聲望才能做到這一點... – Pozinux
歡迎隨時 – Alex