Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate the screen to landscape (or portrait) by programmable way?

Tags:

android

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.

like image 756
Ferdinand Avatar asked Mar 28 '10 06:03

Ferdinand


People also ask

How do I force my Android screen to rotate?

Use Rotation Control to force screen orientation of Android devices. Once you've installed, open the app and just tap to turn it on. You can even start it when you restart your phone. This will help you when you don't want to open the again and again after every reboot.


2 Answers

Try this:

Activity.setRequestedOrientation() 

with these parameters:

ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

Check this for further reference

like image 120
systempuntoout Avatar answered Oct 02 '22 05:10

systempuntoout


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);
}
like image 20
Vishwanath Avatar answered Oct 02 '22 05:10

Vishwanath