Android 8.1屏幕方向问题:翻转以横竖屏 [英] Android 8.1 screen orientation issue: flipping to landscape a portrait screen
问题描述
我以肖像模式进行所有活动,但我用来播放始终为横向的视频的活动除外。我发现,每次打开并关闭视频活动时,在Android 8.1上,即使清单上的活动设置为人像,上一个活动也会变为横向。
I have all activities in portrait mode except the one that I use to play a video that is always landscape. I found that on Android 8.1 every time I open the video activity and close it the previous activity go to landscape even it's set to "portrait" on the manifest.
- 有时候去肖像,然后去风景,并保持风景。
- 有时去肖像,然后去风景到风景,最后再次画像。
只有在从某个活动恢复为风景后,才会发生这种情况。
This is only happening when a go back from a activity that it's landscape.
有人在经历吗?
谢谢。
编辑
我在Google上报告了该错误: https://issuetracker.google.com/issues/69168442
I report the bug on Google: https://issuetracker.google.com/issues/69168442
编辑2
在Android 9上似乎已修复
It seems fixed on Android 9
推荐答案
只是在我自己的应用中遇到了这个问题。
Just came across this problem in my own app.
适用于我的解决方案如下:
The solution that works for me is as follows:
onCreate(){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
}
onPause(){
if (android.os.Build.VERSION.SDK_INT >= 27) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
}
}
onResume(){
if (android.os.Build.VERSION.SDK_INT >= 27) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
}
}
上面的代码应该在以下活动中横向模式(即第二个活动,以及您从中按下后退按钮的活动)
The above code should go in the activity that is in landscape mode (i.e. the second activity, and the one you press the back button from)
我想指出的是,该解决方案不是我自己的,我有从以下链接的20号帖子中获取了此信息(在OP中也已注明):
I would like to point out that this solution was not my own, and I have taken it from the #20 post at the following link (which is also noted in the OP):
https://issuetracker.google.com/issues/69168442
我只是觉得这可能会更简单供人们访问,而不必搜索其他页面。
I just thought it might be easier for people to access if they don't have to search another page for it.
这篇关于Android 8.1屏幕方向问题:翻转以横竖屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!