[英]Orientation issue in Android 7.1.1 and above
When the app is launched in landscape mode it is opening in landscape mode and switching back to portrait evethough orientation is set to portrait programatically. 当应用以横向模式启动时,它将以横向模式打开并切换回纵向,但通过编程方式将方向设置为纵向。 I suppose app should stay in portrait mode no matter in which mode you launch when screen orientation is set to portrait programatically.
我想无论将屏幕方向以编程方式设置为纵向时,无论以哪种模式启动,应用都应保持纵向模式。 I know if we set screen orientaion to portrait in Manifest will solve this but I need to set orientaion programatically.
我知道如果在Manifest中将屏幕方向设置为纵向将解决此问题,但是我需要以编程方式设置方向。 Let me know if anyone faced this issue or have any idea to fix this.
让我知道是否有人遇到此问题或有任何解决办法。 This is happening only when app is launched.
这仅在启动应用程序时发生。 Next time when the screen is rotated it is working fine.
下次旋转屏幕时,它可以正常工作。
Below is the code I am using to lock orientaion to portrait, 以下是我用于将方向锁定为人像的代码,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_main);
}
this code working fine in below Android 7.1.1. 此代码在Android 7.1.1以下版本中可以正常工作。
The below code works for me on all devices: 以下代码适用于所有设备:
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} ... enter code here ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.