Have A Fixed Orientation Based On Screen Size
Solution 1:
Instead of fixing the orientation on the manifest, you could use setRequestedOrientation
. On the onCreate
method of each activity, check if you are on a tablet or smartphone and set the desired orientation.
Another option could be Creating Multiple APKs for Different Screen Sizes, depending on your needs.
Solution 2:
Yes, you can create the layout for the same. See accepted answer here: SO
It will solved your question.
UPDATE
If you want to set it as per the Screen size then please see below code to get the density of the screen. and based on that and Screen Size, you have to set the orientation programetically.
Code to check Density:
publicvoidScreenSupport(){
Displaydisplay= getWindowManager().getDefaultDisplay();
DisplayMetricsdm=newDisplayMetrics();
display.getMetrics(dm);
intwidth= display.getWidth();
intheight= display.getHeight();
intdensity= dm.densityDpi;
StringdensityString=null;
if(density == DisplayMetrics.DENSITY_HIGH) {
densityString = "HDPI";
} elseif(density == DisplayMetrics.DENSITY_MEDIUM) {
densityString = "MDPI";
} elseif(density == DisplayMetrics.DENSITY_LOW) {
densityString = "LDPI";
}elseif(density == DisplayMetrics.DENSITY_DEFAULT) {
densityString = "DEFAULT";
}
/* System.out.println("Screen Height is: "+height+ " and Width is: "+width);
System.out.println("Screen Support: "+densityString);*/
}
Solution 3:
Just remove android:screenOrientation="portrait"
from manifest.xml
And add layout-large-land,layout-small-land and also keep layout-large,layout-small folders.
Hope it works for you. Enjoy coding :)
Post a Comment for "Have A Fixed Orientation Based On Screen Size"