Different layouts depending on the screen resolution – Android… here is a solution to the problem.
Different layouts depending on the screen resolution – Android
I’m trying to use different layouts for different screen resolutions
I’ve made it.
My problem is, I only need landscape orientation for the Large and Xlarge layouts
and
ordinary and small portraits. I
only use Layout-large-land and Layout-xlarge-land in my
res folder, which also comes with portrait orientation. Similarly, for Normal and Small, it also comes with portrait orientation
Landscape. So what can I do to programmatically set the orientation based on the screen resolution
In java files??
Can anyone help me??
Solution
You need to call it in the activity’s onCreate method:
if ((this.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) <= Configuration.SCREENLAYOUT_SIZE_NORMAL) {
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}