Friday, October 31, 2014

Know when the orientation changes in Android

This code snippet will make you know when the user changes the Orientation of the application screen.
<activity
android:name=".MyActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize">
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
Log.d("SOMU","Orientation Changed to Landscape mode");
}
else if(newConfig.orientation==Configuration.ORIENTATION_PORTRAIT){
Log.d("SOMU","Orientation Changed to Potrait mode");
}
}
view raw MyActivity.java hosted with ❤ by GitHub

This code will make the orientation fix the activity to Landscape
<activity
android:name=".MyActivity"
android:label="@string/app_name"
android:screenOrientation="landscape">

No comments:

Post a Comment