开发者

Android: rotating to landscape

开发者 https://www.devze.com 2023-03-23 14:07 出处:网络
I have an Android app with an activity that processes the orientation change (android:configChanges=\"keyboardHidden|orientation\" in the manifest). It also has an onConfigurationChanged handler that

I have an Android app with an activity that processes the orientation change (android:configChanges="keyboardHidden|orientation" in the manifest). It also has an onConfigurationChanged handler that calls the superclass.

After the device is rotated, the activity remains in portrait mode. And the whole screen is in bizarre state where the X axis goes physically bottom to top, the Y axis goes left to right, the status bar runs along the left screen edge, and all text goes physi开发者_如何学编程cally up. It's as if the system is forced to not acknowledge the orientation change.

What I would really like to do, I'd like to avoid activity restart, but process the orientation change with few carefully placed layout property flips. However, in the abovementioned state of the GUI I cannot do that. Reloading the main layout file makes no change.

Question - how do I tell the system to switch physical orientation, so that XY axes go the way they should?

EDIT: and here's a curious data point: on all onConfigChanged calls, the newConfig.orientation is 1.


You really shouldn't use android:configChanges. This technique is considered as a last resort. Please read Handling Runtime Changes for more details.

Brief explanation: if you used android:configChanges its your responsibility to handle configuration change event and reload the UI resources for new configuration. When onConfigurationChanged() is called, getResources() already points to correct resources from new configuration. You only need to manually re-set all layouts, strings, dimensions, drawables, etc. with new (potentially changed) values.


You also didn't mention reasons why you decided to go with configChanges, instead of normal Activity workflow. This might have been useful to give you some alternatives.


The attribute android:screenOrientation="portrait" in the manifest was to blame. With this attribute present, even letting the system restart the activity won't switch the screen to true landscape mode.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号