5

我目前正在制作一个非常密集且不能很好地处理屏幕旋转的动态壁纸。

事实上,没有调用 onSurfaceChanged,壁纸被破坏并显示空白屏幕!

这是我在 onSurfaceChanged 方法中的内容:

@Override
    public void onSurfaceChanged(SurfaceHolder holder, int format,
            int width, int height) {
        // TODO Auto-generated method stub
        super.onSurfaceChanged(holder, format, width, height);

        mRatio = (float) width / height;
        if (mRatio > 1) {
            orientation = 0;
        }
        if (mRatio < 1) {
            orientation = 1;
        }
        setRunning(true);
        Log.i(TAG, "Screen Rotation...");
        mHandle.post(r);
    }

我很肯定这个方法不会被调用,因为没有日志消息。

为什么会发生这种情况以及处理屏幕旋转的一些技术是什么?莫非我的动态壁纸密集到无法呼唤?

此外,onVisibilityChanged 也没有被调用,当我在模拟器上打开应用程序时,没有日志消息:

@Override
    public void onVisibilityChanged(boolean visible) {
        // TODO Auto-generated method stub
        super.onVisibilityChanged(visible);
        if (visible) {
            setRunning(true);
            Log.i(TAG, "Visible...");
            mHandle.postDelayed(r, 2000);
        } else {
            setRunning(false);
            Log.i(TAG, "Invisible...");
            mHandle.removeCallbacks(r);
        }
    }
4

1 回答 1

1

在您的清单中,声明:

    <activity android:name=".YourActivityName"
              android:configChanges="keyboardHidden|orientation"
    </activity>

只有在清单中onSurfaceChanged声明 - 属性时才会调用您的- 方法!configChanges

关于您的第二个问题:onVisibilityChanged这不是您对名称的期望:

Called when the window containing has change its visibility (between GONE, INVISIBLE, and VISIBLE). Note that this tells you whether or not your window is being made visible to the window manager; this does not tell you whether or not your window is obscured by other windows on the screen, even if it is itself visible.

onPause()您需要通过和检查您的应用是否对用户“可见”onResume()

于 2012-06-17T13:15:22.357 回答