Reputation: 6891
I have an application and the problem is it needs to support tablets and phones. However on tablets you can use landscape instead of portret because it's big enough to display everything. However on a phone this screws everything up, because the screen is too small.
I wanted to disable landscape view for phones and not tablets.
I see that you can define portrait in the manifest.xml file, but is it possible to disable it depending on the layout xml ?
For example:
-phones use layout-hdpi -tablets default to layout
If a device uses layout-hdpi then portrait only should be enabled, else it can go into landscape.
Upvotes: 2
Views: 520
Reputation: 2808
An alternative to the answer given by @pjanecze is to do this in code:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
I call this in my base Activity onCreate method. For some reason the manifest method wasn't working for me.
Some users report problems with the code above being ignored however this can be fixed by first setting the requested orientation to something else first:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Upvotes: 0
Reputation: 3175
I did this by following:
This values came from source sdk so if you want different check it out (search for screenOrientation in this link).
I hope this solution will help you.
Upvotes: 1