简体   繁体   English

即使将方向设置为纵向,屏幕仍然可以旋转

[英]Screen still can rotate even if orientation is set to Portrait

I know the tile seems to be very confusing, but yeah, it happened to my application. 我知道磁贴似乎非常令人困惑,但是,是的,它发生在我的应用程序中。 Ok, here's the story. 好的,这是故事。

Here's the key settings in Manifest: 以下是清单中的关键设置:

android:screenOrientation="portrait"
android:configChanges="orientation|screenSize|keyboardHidden"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"

In my Activity.java, I also override onConfigurationChanged(Configuration config) , which will print out current orientation. 在Activity.java中,我还重写了onConfigurationChanged(Configuration config) ,它将打印出当前方向。

Here comes the most interesting part. 这是最有趣的部分。 I start a rotatable Application, say Gallery (assume it can rotate), from my application in landscape using Intent. 我使用Intent从风景中的应用程序中启动一个可旋转的应用程序,例如Gallery(假设它可以旋转)。 Keep the phone in landscape, and press back key. 将手机放在横向,然后按返回键。 The newly launched activity, in this case Gallery, will quit, and my application will restart. 新启动的活动(在本例中为Gallery)将退出,我的应用程序将重新启动。 In theory, my application should display in portrait since I have set the screenOrientation to portrait. 从理论上讲,由于我将screenOrientation设置为纵向,所以我的应用程序应该以纵向显示。 However, in reality, my application just stays in portrait for 1 second, and then jumps to landscape, and jumps back to portrait again. 但是,实际上,我的应用程序仅停留在纵向状态1秒钟,然后跳至横向,然后再次跳回纵向。

I start a thread to print out requestedOrientation of my application after onRestart is called. 我启动一个线程打印出requestedOrientation我的申请后onRestart被调用。 And I find out that the output is always "1", which is "portrait". 而且我发现输出始终为“ 1”,即“肖像”。 Yet, the output from onConfigurationChanged gives my a current orientation of landscape! 但是, onConfigurationChanged的输出给出了我当前的风景方向!

So, I'm totally confused. 所以,我很困惑。 How can this happen? 怎么会这样 Can someone give me some advice? 有人可以给我一些建议吗?

May be you use screen orientation in an activity. 可能是您在活动中使用屏幕方向。 But another activity will be rotate. 但是另一个活动将是轮换。 in below example ActivityA's orientation will not change but ActivityB will be rotate. 在下面的示例中,ActivityA的方向不会改变,但ActivityB会旋转。 If you write android:screenOrientation="portrait" in app tag and not mention anything in activity. 如果您在应用代码中编写了android:screenOrientation =“ portrait”,但未在活动中提及任何内容。 It doesn't work anything. 它没有任何作用。 So please mention screenOrientation in activity. 因此,请在活动中提及screenOrientation。

<activity
   android:name=".ActivityA"
   android:screenOrientation="portrait">
</activity>
<activity
   android:name=".ActivityB">
</activity>

are you using android:screenOrientation="portrait" android:configChanges="orientation|screenSize|keyboardHidden" 您是否正在使用android:screenOrientation="portrait" android:configChanges="orientation|screenSize|keyboardHidden"

inside your application or under activity 在您的应用程序内部或处于活动状态

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何设置方向屏幕“肖像” - How i can set orientation screen 'PORTRAIT' 屏幕方向被强制设置为纵向,但倾斜时活动仍将旋转为横向! 如何强制人像模式? - Screen orientation forced to portrait, but still, the activities will rotate to landscape when tilted!! How to force portrait mode? 如果方向设置为纵向,是否仍能检测到方向变化? - Can orientation changes still be detected if the orientation is set to portrait? Android:即使设备自动旋转屏幕关闭,如何强制反转肖像方向? - Android: How to force reverse portrait orientation even if the device auto-rotate screen is off? 在未启用“自动旋转屏幕”的情况下无法使用反向人像方向 - Can't use reverse portrait orientation without “Auto-Rotate Screen” enabled 屏幕方向为纵向和反向纵向 - Screen orientation to portrait and reverse portrait Android 自定义 SurfaceView 方向无法从纵向旋转到横向 - Android custom SurfaceView orientation can't rotate from portrait to landscape 屏幕方向-反向肖像 - screen orientation - reverse portrait 屏幕方向仅纵向 - screen orientation to portrait only 屏幕旋转后,Android无法设置工具栏标题(平板电脑布局为纵向) - Android can't set toolbar title after screen rotate (tablet layout to portrait)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM