[英]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.