using onOffsetsChanged() to get home screen swipe direction

▼魔方 西西 提交于 2019-11-26 21:44:20

问题


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.

Thank you.


回答1:


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).

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

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



来源:https://stackoverflow.com/questions/6637753/using-onoffsetschanged-to-get-home-screen-swipe-direction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!