Immanuel

Thursday, October 18, 2012

Handling Orientation changes - Android

There is a difficulty for the UI/UX designers to design the User Interface for the android application. The major problem i see is the orientation change, Usually smart phones have two orientations they are portrait, Landscape. If you design the UI in the portrait orientation it will be in the vertical manner (i.e) the height is larger than the width . When you see in the Landscape orientation it is in the horizontal manner (i.e) the width is larger than the height.

To over come this problem i have used two different layouts in the same name.

E.g

File:res/layout/activity-main.xml

Design for portrait orientation in this file




This file will be loaded for the portrait orientation.

create a new folder named layout-land under the res folder. Now create the new xml file in the same name, in this example it is activity-main.xml

File:res/layout-land/activity-main.xml

Design for landscape orientation in this file



This file will be loaded for the Landscape orientation.

These layouts will be automatically loaded by the android system when you change the orientation. The data you typed in the fields will be available even after changing the orientation because it it will not destroy the activity.

Use Ctrl+F12 to switch the orientation of the emulator in Linux (Ubuntu).

Happy Hacking...

No comments:

Post a Comment

Twitter Bird Gadget