动态壁纸图像

Poz*_*nux 4 android image bitmap wallpaper live

(对不起,我的英文不太好......希望你能理解我)

我的朋友是一个非常好的抽屉.我想帮助他成为一个好抽屉,让他成为一个用他的绘画动画的动态壁纸.

我希望他能画几帧并使用这些帧来制作动态壁纸,一个接一个地显示它们.

我正在努力展示一张图片,然后等一下,然后显示下一张图片.我很确定我不能成功,因为我没有使用正确的方法......

这是我到目前为止所做的事情:

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);
        }
    }
}
}
Run Code Online (Sandbox Code Playgroud)

此代码只是显示图片太快,因为我不知道如何在diplaying图片之间等待...

任何人都可以给我一些提示或向我展示另一个解决方案的例子吗?

非常感谢 !

更新:

我通过添加Runnable解决了我的问题:

private final Runnable drawRunner = new Runnable() 
    {
        @Override
        public void run() {
            drawFrame();
        }

    };
Run Code Online (Sandbox Code Playgroud)

然后添加:

    handler.removeCallbacks(drawRunner);
        if (visible) 
        {
           handler.postDelayed(drawRunner, 1000); // delay 1 sec
        }
Run Code Online (Sandbox Code Playgroud)

在drawFrame()的末尾.

希望这会对某人有所帮助.

Ale*_*lex 6

使用这个开源项目为您的朋友创建漂亮的动态壁纸

链接是从电话库中读取的,您可以编辑它以从项目中的文件夹中读取,只需按原样使用即可.

或使用此链接进行其他动态壁纸项目