Orientation Change on Simulator vs Android

Hi

I am trying to handle orientation changes by positioning elements relative to the current display.contentWidth and display.contentHeight. When I test this on the simulator, display.contentWidth and display.contentHeight have the values 320 and 480 respectively in portrait mode. In landscape mode, these values exchange places and become (width=480 and height=320) which is expected.

However, when I try this on an Android device the values do not change when the orientation changes. display.contentWidth is always 320 and display.contentHeight is always 480, regardless of orientation. The system.orientation value does correctly change to “landscapeLeft” or “landscapeRight” in landscape mode, so that seems to be working fine, but the content dimensions are fixed.

My build.settings file has this section:

orientation = {         default = "portrait",     supported = { "portrait", "landScapeLeft", "landScapeRight" }     }

The config.lua file has this in it:

application = {     content = {         width = 320,         height = 480,          scale = "letterBox",         fps = 60,             },

Am I doing something wrong? Missing a setting somewhere?

You have typos in your “build.settings” file.  It should be “landscapeLeft” and “landscapeRight” with a lower case ‘s’.  Those orientation settings are case sensitive.  Since the casing is wrong, the only valid setting is “portrait”, which is why your app is not changing orientation.

   http://docs.coronalabs.com/guide/distribution/buildSettings/index.html#device-orientation

Also note that your app will receive orientation events for orientations that your app does not support.  This is the expected behavior.  This allows you to do something like camera apps do where they typically have a fixed orientation, but will rotate its controls when change the device orientation.

Also, I recommend that you use the “resize” event instead of the “orientation” event.  See the details documented here…

   http://docs.coronalabs.com/api/event/resize/index.html

Thank you, that solved the problem!

You have typos in your “build.settings” file.  It should be “landscapeLeft” and “landscapeRight” with a lower case ‘s’.  Those orientation settings are case sensitive.  Since the casing is wrong, the only valid setting is “portrait”, which is why your app is not changing orientation.

   http://docs.coronalabs.com/guide/distribution/buildSettings/index.html#device-orientation

Also note that your app will receive orientation events for orientations that your app does not support.  This is the expected behavior.  This allows you to do something like camera apps do where they typically have a fixed orientation, but will rotate its controls when change the device orientation.

Also, I recommend that you use the “resize” event instead of the “orientation” event.  See the details documented here…

   http://docs.coronalabs.com/api/event/resize/index.html

Thank you, that solved the problem!