2011-09-23 104 views
13

我想仅在设备上以横向模式运行Hello World示例应用程序。仅在横向模式下运行应用程序?

如果设备更改为人像,我想再举一个烤面包机。例如“请更改为横向模式以运行您的应用程序”。

我该怎么做?

回答

37

您可以通过编程去两个如下:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

或也清单文件,你可以给这里

<activity android:name=".YourActivity" android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation"/> 
+1

大ans ....... @ android杀手: – pratik

8

这在您的清单文件添加到您的活动代码:

android:screenOrientation="landscape" 

这将解决您的方向为横向模式,你需要不显示任何祝酒用户。

0

你可以尝试这样的事情

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth(); 
int height = display.getHeight(); 

Log.v("log_tag", "display width is "+ width); 
Log.v("log_tag", "display height is "+ height); 

if(width<height){ 
    Toast.makeText(getApplicationContext(),"Device is in portrait mode",Toast.LENGTH_LONG).show(); 
} else { 
    Toast.makeText(getApplicationContext(),"Device is in landscape mode",Toast.LENGTH_LONG).show(); 
} 
相关问题