相关疑难解决方法(0)

屏幕方向锁定

是否有可靠的方法来锁定所有Android设备上的屏幕方向?以下代码适用于我的Nexus S和其他手机,但出于某种原因,ROTATION_90对应于Xoom上的SCREEN_ORIENTATION_REVERSE_PORTRAIT.

有没有办法可靠地将旋转映射到方向?

private void lockScreenOrientation() {
    if (!mScreenOrientationLocked) {
        final int orientation = getResources().getConfiguration().orientation;
        final int rotation = getWindowManager().getDefaultDisplay().getOrientation();

        if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
            if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            }
            else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            }
        }
        else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) {
            if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
            }
            else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
            }
        }

        mScreenOrientationLocked = true;
    }
}

private void unlockScreenOrientation() { …
Run Code Online (Sandbox Code Playgroud)

android locking screen rotation orientation

34
推荐指数
4
解决办法
4万
查看次数

在android中更改特定页面的方向

我正在使用 Qt 和 C++ 开发一个 android 应用程序。我的整个应用程序都有纵向。但是当我播放视频时,我想将方向更改为横向,视频结束后它应该再次更改为纵向。

所以问题是如何在适用于 Android 的 Qt/C++ 应用程序中将屏幕设置为横向或纵向模式。

c++ java qt android qtandroidextras

2
推荐指数
1
解决办法
848
查看次数

标签 统计

android ×2

c++ ×1

java ×1

locking ×1

orientation ×1

qt ×1

qtandroidextras ×1

rotation ×1

screen ×1