Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图让动态壁纸中的背景在用户更改主屏幕时的滚动方面表现得像普通壁纸。我知道这需要的方法是 onOffestsChanged,但我似乎无法让它工作。
有没有人有建议或代码片段来让它工作?
让你的引擎实现 onOffsetsChanged。xOffset 变量是一个从 0 到 1 的浮点值,其中 0 是最左边的屏幕,1 是最右边的屏幕。使用屏幕的宽度(来自 onSurfaceChanged)和图像的宽度来确定绘制图像的左侧 x 坐标。
(screenWidth - yourImageWidth) * (1 - xOffset);
screenWidth > yourImageWidth这应该适用于两者screenWidth < yourImageWidth.
screenWidth > yourImageWidth
screenWidth < yourImageWidth.