Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change orientation at runtime

I'm new to android my question is, Is it possible to change orientation programmatically? If yes, how can we do that?

like image 285
jayellos Avatar asked Mar 23 '12 10:03

jayellos


People also ask

How do I change the orientation of a game?

The display orientation of the application may be locked. In the game, tap the “Settings” button in the toolbar. In the “Settings” display, scroll down to the “Lock Orientation” option. Review the current setting to ensure it is either set to “auto” or your preferred fixed orientation.

How do you force orientation in unity?

You can define your app orientation within Unity under Player Settings -> Resolution and Presentation -> Orientation. Our Core Samples use this to lock to portrait mode.

How do I change the orientation of my emulator?

You can change the screen orientation by clicking either of the "rotate" buttons in that side panel. Just click on Rotate button to change the landscape to portrait and vice versa. Unfortunately, although this rotates the emulator depiction, it doesn't signal the applications to rotate.


2 Answers

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Also add this in your manifest file (under activity):

android:configChanges = "orientation"
like image 163
Bigflow Avatar answered Nov 10 '22 01:11

Bigflow


Yes, use setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); to force orientation

like image 36
Alix Bloom Avatar answered Nov 10 '22 00:11

Alix Bloom