我为我的应用程序设置屏幕方向的代码无法正常工作?
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:
CAn i prevent activity to reload when call is recieved specially problem is with list view it just flushed.
请回答编辑2
答案 0 :(得分:1)
在应用
下的活动代码中添加此内容android:screenOrientation="portrait"
答案 1 :(得分:1)
我不太了解您的标准,但设置屏幕方向的方法是:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
或
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
答案 2 :(得分:1)
在你的androidmanifest中使用这个
android:configChanges="orientation"
for landscape
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
如果你想要未指定的
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
答案 3 :(得分:0)
我的标准回答了一些
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);