使用onOffsetsChanged()来获取主屏幕滑动方向屏幕、方向、onOffsetsChanged

2023-09-05 00:52:33 作者:浅︶﹋★、色调

我的工作我的动态壁纸,我希望它滚动在屏幕就像一个普通壁纸一样。我知道我需要使用onOffsetsChanged(),但参数会告诉我的方向的主屏幕被刷?好像xOffset总是返回正值,无论哪种方式,屏幕幻灯片。

I'm working on my Live Wallpaper and I want it to scroll with the screen like a normal wallpaper does. I know I need to use onOffsetsChanged() but which parameter will tell me the direction that the home screen is being swiped? It seems like xOffset always returns a positive value no matter which way the screen slides.

感谢你。

推荐答案

方向本身并不能帮助你:你需要知道确切的偏移,因为用户可能已跃升几个屏幕一次(使用弹出如最多显示迷你版本的所有主屏幕的)。

The direction alone will not help you: you need to know the exact offset, because the user may have jumped several screens at once (e.g. by using a pop-up that displays mini-versions of all the home screens).

一般来说,要保存你在onOffsetsChanged得到xPixel值,然后用这个翻译画布。

Generally speaking, you want to save the xPixel value you get in onOffsetsChanged, then use this to translate your canvas.

请参阅我的两个答案如下: onOffsetsChanged:将位图 Android的动态壁纸的重新调整

See my two answers below: onOffsetsChanged: move Bitmap android live wallpaper rescaling