相关疑难解决方法(0)

Android:允许平板电脑的纵向和横向,但强制手机上的肖像?

我希望平板电脑能够以纵向和横向(sw600dp或更高)显示,但手机仅限于纵向.我找不到有条件选择方向的方法.有什么建议?

android tablet screen-orientation

181
推荐指数
8
解决办法
8万
查看次数

屏幕方向锁定

是否有可靠的方法来锁定所有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万
查看次数