开发者

Handling orientation changes conditionally

开发者 https://www.devze.com 2023-02-14 13:38 出处:网络
I added android:configChanges=\"orientation\" and I override onConfigurationChanged().What I\'d like to do is allow the landscape orientation change only if the device has a tablet-sized display resol

I added android:configChanges="orientation" and I override onConfigurationChanged(). What I'd like to do is allow the landscape orientation change only if the device has a tablet-sized display resolution setting (shorter side greater than 480px - suggestions for better way of handling this are welcome!). I was thinking that this would work one of two ways, but neither is working in my tests either on my phone or in the emulator.

My first idea was to not call the super class' implementation of onConfigurationChanged(), but I get an exception thrown that complains about me not calling the super class.

My second idea was to just manually set newC开发者_运维百科onfig.orientation to Configuration.ORIENTATION_PORTRAIT before passing it to the super class. In between my Activity and the actual Activity class in the framework I have an ActivityBase class that I use where I am overriding this as well. I can toast the value of newConfig.orientation in ActivityBase to see that the configuration object indeed being passed around does have the new value, but it is ignored and the orientation change has already occurred.

Where can I put code that allows me to conditionally short circuit the orientation change in some cases and allow it in others?


I would set the requested orientation to fix in the Activity onCreate() method, something like this:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

if the Display isn't a xhdmi Display or has the required resolution.

0

精彩评论

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