How do you find out what orientation the phone is in?

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

Simple question:
How do you find out what orientation the phone is in?

I plan to do this in an If statement in the Activity_Resume sub.

Thanks.
 

rleiman

Well-Known Member
Licensed User
Longtime User
Hi EPS,

I used it in this code to adjust the layout of some buttons.

B4X:
' Layout the buttons according to the orientation of the device.
   '---------------------------------------------------------------
   If Activity.Width > Activity.Height Then 
   
      ' The device is in landscape.
      '----------------------------
      panelButtonBackground.Left = 10dip
      panelButtonBackground.Top = 15dip
      panelButtonBackground.Height = buttonVisits.Height + 25dip
      
      buttonVisits.Left = 10dip
      buttonVisits.Top = 15dip
      buttonVisits.Width = 30%x
   
      buttonMaintenance.Top = 15dip
      buttonMaintenance.Width = 50%x
      buttonMaintenance.Left = Activity.Width - buttonMaintenance.Width - 30dip
   Else

      ' The device is in portrait.
      '---------------------------
      panelButtonBackground.Left = 10dip
      panelButtonBackground.Top = 12dip
      panelButtonBackground.Height = buttonVisits.Height + 20dip
      
      buttonVisits.Left = 10dip
      buttonVisits.Top = 12dip
      buttonVisits.Width = 30%x
   
      buttonMaintenance.Top = 12dip
      buttonMaintenance.Width = 50%x
      buttonMaintenance.Left = Activity.Width - buttonMaintenance.Width - 30dip
   End If
 
Upvote 0

eps

Expert
Licensed User
Longtime User
This is what I thought. I create 2 layouts in the designer. 1 portrait and 1 landscape and then position elements in both, but each to their own!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…