How can I force screen orientation on some layout where the layout have several versions , I'm trying to lock portrait mode for normal screens(phones) while on the other hand I want landscape mode to be for tablet devices
java answers if possible
CodePudding user response:
Easiest way:
values-sw300.xml (or whatever other size definition you have of "tablet")
<bool name="isTablet">true</bool>
values.xml
<bool name="isTablet">false</bool>
main_activity.java
if(!getResources().getBoolean(R.bool.isTablet) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
This will lock the orientation, only if it chooses the default resource file- only if its smaller than a tablet.