disable landscape mode?
如何禁用我的Android应用程序中某些视图的横向模式?
Add android:screenOrientation="portrait"
to the activity in the AndroidManifest.xml. For example:
<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" />
EDIT: Since this has become a super-popular answer, I feel very guilty as forcing portrait is rarely the right solution to the problems it's frequently applied to.
The major caveats with forced portrait:
retainInstance
fragments. So most apps should just let the phone sensors, software, and physical configuration make their own decision about how the user wants to interact with your app. A few cases you may still want to think about, though, if you're not happy with the default behavior of sensor
orientation in your use case:
nosensor
for the orientation. This forces landscape on most tablets and portrait on most phones, but I still wouldn't recommend this for most "normal" apps (some users just like to type in the landscape softkeyboard on their phones, and many tablet users read in portrait - and you should let them). sensorPortrait
may be better than portrait
for Android 2.3+; this allows for upside-down portrait, which is quite common in tablet usage. 在阅读这篇文章之前,我并没有意识到AndroidManifest.xml
文件的切换,所以在我的应用程序中我使用了它:
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Fixed Portrait orientation
Add this android:screenOrientation="portrait"
in your manifest file where you declare your activity like this
<activity android:name=".yourActivity"
....
android:screenOrientation="portrait" />
If you want to do using java code try
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
before you call setContentView
method for your activity in onCreate()
.
Hope this help and easily understandable for all...
链接地址: http://www.djcxy.com/p/16118.html上一篇: 如何从应用程序的(布局)XML变量中获取Manifest版本号?
下一篇: 禁用横向模式?