简体   繁体   English

为什么xstep会以负值返回

[英]Why does xstep get returned as a negative value

I have the following snippet of code extending GLWallpaperService in an app: 我有以下代码片段在应用程序中扩展GLWallpaperService:

    @Override
    public void onOffsetsChanged(float xOffset, float yOffset,
            float xStep, float yStep, int xPixels, int yPixels) {
    super.onOffsetsChanged(xOffset,yOffset,xStep,yStep,xPixels,yPixels);
    VideoLiveWallpaper.xStep = xStep;
    VideoLiveWallpaper.yStep = yStep;
    Log.w("General", "xStep: " + xStep);
    Log.w("General", "yStep: " + yStep);

When I run this my understanding is that xstep should return a value between 0 and 1, essentially allowing me to determine the number of screens by dividing the xstep value by 1. However, every time I run this on my Sony Xperia Ion the xstep is returned as -1. 运行此命令时,我的理解是xstep应该返回0到1之间的值,从本质上讲,我可以通过将xstep值除以1来确定屏幕数。但是,每次在Sony Xperia Ion上运行xstep时,返回-1。 I have five homescreens setup so this is not just a default for a single homescreen. 我有五个主屏幕设置,所以这不仅仅是单个主屏幕的默认设置。

I have tried searching Google but did not see anyone else who seems to be having the same problem. 我曾尝试搜索Google,但没有看到其他人也遇到同样的问题。 Is this a bug in my particular phone? 这是我特定手机中的错误吗? Is there a better way to determine the number of homescreens and how much a wallpaper should scroll as they move? 有没有更好的方法来确定主屏幕的数量以及墙纸在移动时应滚动多少?

I never did find the reason why this occurs, but I did find another piece of code that addresses the issue. 我从来没有找到发生这种情况的原因,但是我确实找到了另一个解决该问题的代码。 Here is the relevant portion, in case it helps anyone else: 如果可以帮助其他人,这是相关的部分:

 if (xStep <= 0.0f && VideoLiveWallpaper.xStep == 0) {
      xStep = xOffset / 2; // originator didn't set step size, assume we're halfway

It seems to work as long as the home screen (middle screen) is up when the wallpaper starts. 只要墙纸开始时只要打开主屏幕(中间屏幕),它就可以正常工作。 That's not perfect, but it works better than my method of assuming 5 screens (xStep = 0.25) in all cases when it's zero... 这不是完美的,但是它比我假设零的所有情况下假设有5个屏幕(xStep = 0.25)的方法要好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM