Android Orientation Changes

So we have a requirement, where sometimes your screen needs to be one orientation for a certain situation or screen size.. So that rules out using:

android:screenOrientation="sensorPortrait"  

As this will stop your Activity from using all orientations in other sizes/views etc.

So, what do we do?

public void onCreate(Bundle savedInstanceState) {  
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  //If normal do..
  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  //Else do something else  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
 } 

Job done! You can change the orientation to your hearts content. Great for, forcing your user into full screen mode landscape when playing a video for example.

comments powered by Disqus