Android动态壁纸onOffsetsChanged xPixelOffset似乎没有返回真实的像素偏移量

发布于 2024-09-08 23:08:20 字数 393 浏览 0 评论 0原文

我正在编写一个动态壁纸,并使用该功能:

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

查看用户何时滑动到另一个屏幕,我使用 xPixelOffset 来查看屏幕移动的距离(以像素为单位),但它不会返回我期望的像素数。

对于桌面的 5 个屏幕中的每一个,它显示的像素偏移量为 0、-80、-160、-240、-320,但是我希望它每次都会偏移屏幕的宽度(240px 而不是 80px) )

我错过了什么吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

因为看清所以看轻 2024-09-15 23:08:20

您会注意到,当您滚动时,主屏幕的前景(图标、小部件等)会向左或向右移动全屏宽度,但背景图像(或动态壁纸)仅移动一小部分。那个宽度。最明显的结果是视差滚动效果。

换句话说,端到端的 5 个屏幕总计约为 1200 像素(5 x 屏幕宽度),但同一显示器上壁纸的最大宽度约为 480 像素(2 x 屏幕宽度),因为背面不会像前面那样滚动。

因此,偏移量不应用作显示器前景移动多远的度量,而应用作背景移动多远的度量。

因此,您仍然可以从 offsets 参数中获取所需的信息。只是您对该信息的解释必须稍微改变一下。

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.

旧街凉风 2024-09-15 23:08:20

只需将您绘制的画布/位图设置为整个虚拟壁纸的大小(尺寸应为 screenWidth*2、screenHeight),然后使用 xPixelOffset 作为 x 坐标将其绘制到 SurfaceHolder 画布上。这是最简单的方法。

当然,没有法律规定您的虚拟壁纸需要这些尺寸。如果您愿意,它可以以图标的速度滚动。这时您将需要使用 xOffset 值来计算您自己的像素偏移。

Just have your canvas/bitmap that you draw on be the size of the entire virtual wallpaper (which should have dimensions screenWidth*2, screenHeight), and then draw it to the surfaceHolder canvas using the xPixelOffset as the x coordinate. That is the easy way.

Of course there is no law that your virtual wallpaper needs those dimensions. It could scroll along at the speed of the icons if you wish. That's when you'll want to use the xOffset value to figure out your own pixel offset.

樱花坊 2024-09-15 23:08:20
          if(xPixelOffset != 0){
              myXPixelOffset = xPixelOffset*((backgroundWidth - screenwidth)/screenwidth);
          }

背景宽度应为屏幕高度*2

          if(xPixelOffset != 0){
              myXPixelOffset = xPixelOffset*((backgroundWidth - screenwidth)/screenwidth);
          }

backgroundWidth should bee screenHeight*2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文