Android - detect orientation change, but have interface not respond

Deadly 提交于 2019-12-11 04:28:41

问题


Is it possible in Android to capture screen rotate events but not actually have the activity respond to the rotate events?

To make things more difficult, I've got an activity backed by a TabActivity, and in one of the tabs I want to rotate some of the content area on screen - but leave the tab in portrait mode.

I've tried setting the activity orientation to portrait in the manifest, but then I no longer get the onConfigurationChanged(..) events. However, If I remove this line, the whole tab rotates as well.

Any help appreciated!


回答1:


Set the orientation to portrait mode in the manifest as you did, but listen directly to the accelerometer sensor (which is the sensor from which Android derives the orientation of the device) updates and parse them yourself to know when the orientation changed.

It's actually quite easy to do. See here for an example: http://www.anddev.org/accessing_the_accelerometer-t499.html




回答2:


You might want to add "orientation" to activity's configChanges property in AndroidManifest.

android:configChanges="orientation"

http://androidappdocs.appspot.com/guide/topics/manifest/activity-element.html#config



来源:https://stackoverflow.com/questions/5644645/android-detect-orientation-change-but-have-interface-not-respond

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!