5

I'm trying to get a background in a live wallpaper to behave like a regular wallpaper with regard to scrolling when the user changes homescreens. I know the method required for this is onOffestsChanged, but I can't seem to get it working.

Does anyone have advice or a code snippet to get this working?

Kara
  • 6,115
  • 16
  • 50
  • 57
brmcmaho
  • 409
  • 5
  • 9

1 Answers1

7

Have your engine implement onOffsetsChanged. The xOffset variable is a float value from 0 to 1 with 0 being the leftmost screen and 1 being the rightmost. Use the width of the screen (from onSurfaceChanged) and the width of your image to determine the left x coordinate with which to draw your image.

(screenWidth - yourImageWidth) * (1 - xOffset);

This should work with both screenWidth > yourImageWidth and screenWidth < yourImageWidth.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
caller9
  • 2,207
  • 1
  • 18
  • 11
  • hi caller9 i have done what u say in my code and it works fine on GO LAUNCHER home screen but when i switch to my native android home screen from GO LAUNCHER home screen my live wallpaper stops parallax scrolling.Please help me to get rid of this problem. – himanshu May 23 '13 at 10:54
  • 1
    http://stackoverflow.com/questions/14258234/onoffsetschanged-not-called-by-touchwiz – Swati Rawat Sep 10 '13 at 06:01