Tuesday, February 16, 2016

How to initialize Android program to be portrait or landscape

If you want to disable orientation changes of the phone then you may use this code in the manifest
<activity android:name=".class_name"
//if you want your screen in portrait
android:screenOrientation="portrait" >
//if you want you screen in landscape mode
android:screenOrientation="landscape" >
and if you want your phone to change orientation but prevent the process from restarting then you can use the onConfigurationChanged method in your class:
@Override
public void onConfigurationChanged(Configuration newConfig) {
   // ignore orientation change
   if (newConfig.orientation != Configuration.ORIENTATION_LANDSCAPE) {
       super.onConfigurationChanged(newConfig);
   }
}

No comments:

Post a Comment