tags:

views:

140

answers:

2

Hi guys.

How to rotate the screen to landscape (or portrait) by programmable way? I am trying to make it independent when user rotates the screen.

Is it possible thing ?

Thanks in advance.

+7  A: 

Try this:

Activity.setRequestedOrientation() 

with these parameters:

ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

Check this for further reference

systempuntoout
How do you rotate the screen in Emulator?
Pentium10
Home and PageUp on the numpad, but make sure you take numlock off first.
Steve H
Ctrl+F11 on OSX :)
systempuntoout
+2  A: 

You can try with the sample below...

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
    // You can set the value initially by
    // ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED. Once set it
    // retains it's value. The View will be rendered in the specified
    // orientation using the code below.
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
Vishwanath