仅在横向模式下运行应用程序?
问题描述:
答
您可以通过编程去两个如下:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
或也清单文件,你可以给这里
<activity android:name=".YourActivity" android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation"/>
答
这在您的清单文件添加到您的活动代码:
android:screenOrientation="landscape"
这将解决您的方向为横向模式,你需要不显示任何祝酒用户。
答
在你的manifest资源配置文件(XML)
<activity android:name=".ActivityName" android:screenOrientation="landscape">
</activity>
指这也Is that possible to check was onCreate called because of orientation change?
答
可以使用configChanges
-attribute你想赶上为屏幕方向变化的活动。
之后,活动中的onConfigurationChanged()
-method将在方向更改时调用。
要检查哪个方位当前显示的,请在此较早的帖子:Check orientation on Android phone
之后,你可以炫耀你的消息或做任何你喜欢(当然你也可以将它设置为只在山水秀) 。
答
你可以尝试这样的事情
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();
}
大ans ....... @ android杀手: – pratik