I am not an expert, but this works for me, in onCreate():
int display_mode = getResources().getConfiguration().orientation;
if (display_mode == Configuration.ORIENTATION_PORTRAIT) {
setContentView(R.layout.main);
} else {
setContentView(R.layout.main_land);
}
source
share