Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android中我的应用程序中的屏幕旋转问题?_Java_Android_Rotation_Screen Orientation - Fatal编程技术网

Java android中我的应用程序中的屏幕旋转问题?

Java android中我的应用程序中的屏幕旋转问题?,java,android,rotation,screen-orientation,Java,Android,Rotation,Screen Orientation,我为我的应用程序设置屏幕方向的代码不起作用我的手机挂起 Display display = getWindowManager().getDefaultDisplay(); float width = display.getWidth(); float height = display.getHeight(); if (width>height) { setRequestedOrientation(ActivityInfo.SCREEN_OR

我为我的应用程序设置屏幕方向的代码不起作用我的手机挂起

 Display display = getWindowManager().getDefaultDisplay();
    float width = display.getWidth();
    float height = display.getHeight();
    if (width>height)
    {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    // then

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
编辑1:已解决

   and also can i prevent the content to reload on screen rotation?
编辑2:


请回答编辑2

将其添加到应用程序下的活动标签中

android:screenOrientation="portrait"

我不太理解您的标准,但设置屏幕方向的方法是:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);


我的标准与答案

Display display = getWindowManager().getDefaultDisplay();
float width = display.getWidth();
float height = display.getHeight();
if (width>height)
{
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
else setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

在你的android menifest中使用这个

android:configChanges="orientation"
风景区

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
如果你想

 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);

或风景。。。无论你想要什么,他都是被要求的,所以你答案的第一部分是正确的。
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);