Android 禁用横向模式
我希望在 Android 应用程序中禁用横向视图。我用过:
<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
它有效,但有一个稍微大的问题。如果我旋转屏幕,活动将重新启动,当它返回时,屏幕仍处于纵向模式。我希望我的应用程序完全忽略设备的位置。如果当我旋转设备时 Activity 重新启动(屏幕变黑几秒钟,然后 Activity 再次以纵向模式显示),则禁用横向视图是没有意义的。
I wish to disable the landscape view in an android application . I've used :
<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
It works but there is a slightly big problem . If I rotate the screen the activity restarts , and when it comes back , the screen is still in portrait mode . I want my app to completely ignore the device's position . There is no point in disabling the landscape view if when I rotate the device the activity restarts ( the screen becomes black for a few seconds , and then the activity appears again still in portrait mode ) .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编写一个类并将其扩展到活动中。在该类中将此代码添加到方法中。
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
然后对要禁用横向模式的活动调用此方法。
write a class and extend it to the activity. In that class add this code to a method.
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Then call this method to the activites to which you want to disable the landscape mode..