An android application I am working on needs to change screen layout only when the screen size is above 7''. I created different layouts for large and xlarge for both land and portrait modes. This seems to have worked well.
I used the following code to determine screen size and change layout accordingly:
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels, height = dm.heightPixels;
double dd = Math.sqrt(width * width + height * height)/dm.densityDpi;
double diagonal = (dd >= (Math.floor(dd) + 0.5) ? Math.ceil(dd) : Math.floor(dd));
if (diagonal < 7) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
The problem:
The layout for screens below 7'' is also changed to landscape mode. The above code could not stop the change. Keep in mind that the layout for below 7'' is also created.
What am I doing wrong here?