Screen orientation based on resolution

Inman

Well-Known Member
Licensed User
Longtime User
I know that you can set the screen orientation in AndroidManifest.xml file, either to a specific orientation or to follow accelerometer. But this has to be done before compiling the app.

I was wondering if this is possible on run time via code. My app provides an option to compare 2 tables side by side. Since landscape orientation provides more width than portrait, I have set in the XML file to make this activity work only in landscape mode. Today I tested the app on a tablet and realised these high resolution screens can accommodate 2 tables side by side in portrait mode itself.

So here is what I want to do:

If 100%x <= 480dip Then orientation = landscape only Else orientation = both

Is this possible?
 

eps

Expert
Licensed User
Longtime User
I've got a similar request, but don't think it's covered with SetOrientation.. I am looking for something more like "AllowOrientation"...

i.e. on small screens and medium screens only allow the App to display in Portrait mode. But for Tablets I want it to allow them to view the App in either Portrait or Landscape. The Portrait views are effectively the same, but the Landscape view will allow me to display the Portrait view and another view alongside it...

or is there another route that should be followed for this, i.e. create a "separate" App i.e. one for phones and one for Tablets? In a way I'm hoping that I don't have to create two versions!!

Found this... Fragments | Android Developers ??
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Hmmm.. just had a thought! If I set the orientation programmatically for lower resolutions will this set those to portrait only? Then larger tablet resolutions can change as the device is rotated.. I hope!
 
Upvote 0

eps

Expert
Licensed User
Longtime User
I think I'm misunderstanding something..

I want the following :

On phones, portrait only.

On tablets, both.

I was thinking that if I detect phones or lower resolution devices, I can set those to Portrait Only otherwise both..? Or does it not work like this? I'll give it a test tonight..

ETA :

Ah ha! Done I left it as Portrait only, then detected the screen height and also checked the scale - as some tablets are 800 and my phone is 800, but 1.5d pixel density. Tablet rotates, but phone doesn't!

Dim resolution As Int
Dim p As Phone
resolution=GetDeviceLayoutValues.Height

If resolution > 800 Then
p.setscreenorientation(-1)
Else If resolution = 800 Then
Dim scale As String
scale=GetDeviceLayoutValues.Scale
If scale = "1.0" Then
p.setscreenorientation(-1)
End If
End If

:sign0060:
 
Last edited:
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User

GetDeviceLayoutValues doesn't necessarily return the largest dimension of a tablet when you ask for "height". It returns the height in its present orientation. For example, if I hold a 1280x800 device in landscape orientation, GetDeviceLayoutValue returns 800 for height, but if I turn it to portrait mode, it returns 1280.

Maybe this is what you wanted -- I couldn't tell. If not, you might want to check out this page in the Documentation Wiki.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Cheers, although as the App initially enforces Portrait only, I think I'm safe on that front. Of course I may be wrong....! But after an initial test it seems to work
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…