Parallax scroll effect live background wallpaper

I am trying to get a background in live wallpapers in order to behave like a regular scroll wallpaper when a user changes home screens. I know that this requires the onOffestsChanged method, but I cannot get it to work.

Does anyone have any advice or piece of code to get this to work?

+5
source share
1 answer

Turn onOffsetsChanged engine. The xOffset variable is a floating point value from 0 to 1, where 0 is the leftmost screen and 1 is the rightmost. Use the screen width (from onSurfaceChanged) and the width of your image to determine the left coordinate x, with which you can make an image.

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

This should work both with screenWidth > yourImageWidthandscreenWidth < yourImageWidth.

+7
source

All Articles