Saturday, September 10, 2011

Orientation change in android

Many times you want to have a different layout for landscape view and another one for portrait view.

The simplest way to achieve this is

1> create folder    /res/layout-land
2> in this folder store your layout xml file for landscape view
3> The xml file name must be same for both portrait and landscape orientations

That's it. Now if the user rotates his screen, automatically the landscape layout will be used


And when user changes orientation, the activity restarts. If you do not want that to happen

Add this line to manifest file

<activity
android:configChanges="orientation|keyboardHidden"
--
>

Now the activity will not restart if the orientation is changed.


No comments:

Post a Comment