8.1.0中的Android屏幕方向问题 [英] Android screen orientation issue in 8.1.0

查看:139
本文介绍了8.1.0中的Android屏幕方向问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android OS 8.1.0中出现问题

Am having issue in Android OS 8.1.0


  • 开始肖像活动(在清单上声明肖像)

  • 启动景观活动(在清单上声明景观)

  • 完成景观活动

  • 再次显示肖像活动,但方向已开始翻转:首先进入纵向模式,然后进入横向模式,最后再次进入纵向。

  • Start a portrait activity (portrait declare on manifest)
  • Start a landscape activity (landscape declare on manifest)
  • Finish the landscape activity
  • Portrait activity is showed again but the orientation start flipping: first in portrait mode, then landscape mode and finally portrait again.

我在google pixel 2 xl设备中观察到了此问题,操作系统版本8.1.0及更高版本(也存在于Android P开发人员预览版中)

I had observed this issue in google pixel 2 xl device with OS version 8.1.0 onwards ( issue present in Android P developer preview1 also)

我也看到有人在Google网上论坛发帖

i saw someone posted in google groups also

https://issuetracker.google.com/issues/69168442

但没有得到任何解决,我该如何解决此问题。?

but didn't get any fix, how can i fix this issue.?

我的应用程序是混合应用程序(cordova ),我还尝试在本机android中复制问题,但本机中不存在问题android示例应用程序

My application is hybrid application (cordova) , I also tried to replicate issue in native android but issue is not there in native android sample app

推荐答案

是的,这是Android 8.1 OS版本中的问题。由于这已经过时了。我们可以解决这些问题。在此特定的API级别,Android OS可能会存储最新的方向值并将其应用于所有屏幕,直到上一个屏幕或该特定屏幕被破坏为止。因此,解决此类型问题的方法是在返回屏幕之前更改方向。
表示:
如果ScreenA处于纵向模式,而screenB处于横向模式,并且如果将屏幕移至 ScreenB即 Landscape(横向),并且如果返回到ScreenA而又不杀死ScreenB(恢复ScreenA),则screenA在景观中可见。
要解决此问题,请在ScreenB的onPause()或OnStop()中强制将ScreenA的方向更改为纵向(以还原ScreenA)。

Yes, This is an issue in Android 8.1 OS version. As this was made obsolete. we can have a work around for these kind of issues. In this particular API level , Android OS might be storing the latest orientation value and is being applied to all the screens until the previous screen or that particular screen is destroyed. So, the work around for this type of issue is to change the orientation before going back to the screen . for ex: If ScreenA is in portrait mode and screenB is in landscape mode and if screen is moved to ScreenB which is Landscape and if you come back to ScreenA without killing ScreenB (restoring ScreenA), screenA also be visible in Landscape. To fix this issue, force change the orientation of ScreenA to Portrait in onPause() or OnStop() of ScreenB(to restore ScreenA).

if (android.os.Build.VERSION.SDK_INT >= 27) {
         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

after this call, ScreenA will be in portrait. Also, in onResume() of ScreenB,

if (android.os.Build.VERSION.SDK_INT >= 27) {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}

这篇关于8.1.0中的Android屏幕方向问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆