Wednesday, October 21, 2009

Orientation independent applications

The Android phones detect orientation changes when you tilt yourIMG_0570 phone from landscape to portrait or vice-versa. It’s a cute feature. Well, most of the time you would be using your phone in the portrait mode. But for the phones that have a full QWERTY keyboard, the orientation automatically changes to landscape mode when you slide out your keyboard. If your application is not designed to handle such orientation changes, the usability of your application might decrease to an extent at which it might get completely unusable, or at the least, very inconvenient for the user.

How to handle it? It is actually very simple. You would have put all your layout xml files in a folder called “res/layout. This is the default location from where the layout files are picked up, i.e , when your phone is in portrait mode. You just need to create one more folder “res/layout-land” where you put you xml files, with the same name, but with a different layout, which would be convenient for the user to view when in portrait mode. This is all you have to do.

Next time, when the orientation is changed, your layout files will be picked up from the layout-land folder, and will be applied to your UI.