简体   繁体   English

锁定屏幕旋转但仍然可以检测到

[英]lock screen rotation but detect it anyway

I m building an app which an a main layout in portrait format 我正在构建一个以纵向格式显示主布局的应用

I locking orientation with 我锁定方向

 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 

However, I need to detect screen orientation changes anyway because I want to load another Activity if the screen is rotated. 但是,无论如何我都需要检测屏幕方向的变化,因为如果屏幕旋转,我想加载另一个活动。

How to do that ? 怎么做 ?

I tryed onConfigurationChanged but it s never called. 我尝试过onConfigurationChanged,但从未调用过。

Some things to look at if onConfigurationChanged isn't firing: 如果onConfigurationChanged没有触发,请注意以下事项:

When you declare the manifest, make sure you have defined at least orientation and screenSize for the activity configChanges. 声明清单时,请确保至少为活动configChanges定义了方向和screenSize。 Like this: 像这样:

<activity android:name="com.test.act" android:configChanges="orientation|screenSize">

Make sure the device doesn't have rotation blocked. 确保设备没有旋转受阻。 For example if you are using a Nexus 7: 例如,如果您使用的是Nexus 7:

http://www.howtogeek.com/120056/how-to-enable-landscape-orientation-on-the-nexus-7s-home-screen/ http://www.howtogeek.com/120056/how-to-enable-landscape-orientation-on-the-nexus-7s-home-screen/

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM