动态壁纸屏幕旋转

时间:2012-06-17 12:23:59

标签: android live-wallpaper screen-rotation

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

事实上,壁纸被破坏并显示一个空白的屏幕,而没有调用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);
        }
    }

1 个答案:

答案 0 :(得分: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()

检查您的应用是否对用户“可见”