Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android live wallpaper onOffsetsChanged xPixelOffset doesn't seem to return the real pixel offset

I am writing a live wallpaper and I use the function:

public void onOffsetsChanged(float xOffset, float yOffset,
            float xOffsetStep, float yOffsetStep, int xPixelOffset,
            int yPixelOffset)

To see when the uses swipes across to another screen, and I used xPixelOffset to see how far the screen has moved in pixels, however it does not return the number of pixels I would expect.

For each of the 5 screens of the desktop it shows the pixel offset to be 0,-80,-160,-240,-320 however I would expect it to be offset by the width of the screen each time (240px rather than 80px)

Am I missing something?

like image 547
stealthcopter Avatar asked Jul 07 '10 09:07

stealthcopter


1 Answers

You'll notice that when you scroll, the foreground of the home screen (icons, widgets, etc.) moves to the left or right by the full screen width, but the background image (or live wallpaper) only moves by a fraction of that width. The obvious result is a parallax-scrolling effect.

To put it another way, end-to-end your 5 screens total something like 1200px (5 x screen width), but the maximum width of a wallpaper on the same display is something like 480px (2 x screen width), because the back doesn't scroll as much as the front.

The offsets, then, should not be used as a measure of how far the display's foreground has moved, but how far the background has moved.

So you're still getting the information that you need from the offsets parameter. It's just that your interpretation of that information has to change a bit.

like image 177
Josh Avatar answered Oct 03 '22 05:10

Josh