-1

i'm trying to draw an image as a background in live wallpaper app, but i don't know how to make it scrolls according to user tap to right/left (just like you set a simple wallpaper, if you move the menu to Rightmost, the background also move to Rightmost), here is the code in a live wallpaper app:

private void drawFrame() {

    SurfaceHolder holder=getSurfaceHolder();
    Canvas c=holder.lockCanvas();

    c.drawBitmap(bg, 0, 0, paint);

    holder.unlockCanvasAndPost(c);

    handler.removeCallbacks(drawThread);
    if (visible) handler.postDelayed(drawThread,100);
}

The above code only draw the background to a canvas, but i want to make it as same as simple wallpaper. For example, a very wide picture, how come it only shows the part that fits on "current" screen. I see other live wallpaper where the picture scrolls as you move to a different workspace left or right...is that an easy option or any other example i can follow?

hkguile
  • 4,235
  • 17
  • 68
  • 139

1 Answers1

0

here is the answer

    private int _xOffset = 0;
    private int _yOffset = 0;

    public void onOffsetsChanged(float xOffset,float yOffset,
        float xStep,float yStep,int xPixels,int yPixels) {
        _xOffset = xPixels;
        _yOffset = yPixels;
        drawFrame();
    }

in the drawFrame() function:

c.drawBitmap(bg, _xOffset, _yOffset, paint);
hkguile
  • 4,235
  • 17
  • 68
  • 139