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

How to rotate the screen to landscape (or portrait) in a programmable way? I try to make it independent when the user rotates the screen.

Is it possible?

Thanks in advance.

+7
android
source share
2 answers

You can try with the example below ...

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

Try the following:

 Activity.setRequestedOrientation() 

with these parameters:

 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ActivityInfo.SCREEN_ORIENTATION_PORTRAIT 

Check this box for future reference.

+10
source share

All Articles