Android Question How to lock activity orientation?

stanks

Active Member
Licensed User
Longtime User
Hi

I have activity 1 with project attributes where i can lock orientation. How to lock orientation on activity 2, 3, etc. which are called from main (1) activity?

thanks
 

AllyAndroid

Member
Licensed User
Longtime User
You can set the orientation of an activity by adding the following:

B4X:
Sub Globals
    ' Phone Variable
    Private ph As Phone
End Sub

B4X:
Sub Activity_Resume
    ' 1 = Portrait
    ' 2 = Landscape
    ' 9 = Reverse Portrait
    ' 8 = Reverse Landscape
    ph.SetScreenOrientation(1)
End Sub

You will need to add this line of code where you want to release the screen orientation:

B4X:
PH.SetScreenOrientation(-1)

Or you can use this function created by Stevel05:

http://www.b4x.com/android/forum/threads/freeze-orientation.41681/
 
Upvote 0

Lello1964

Well-Known Member
Licensed User
Longtime User
You can set the orientation of an activity by adding the following:

B4X:
Sub Globals
    ' Phone Variable
    Private ph As Phone
End Sub

B4X:
Sub Activity_Resume
    ' 1 = Portrait
    ' 2 = Landscape
    ' 9 = Reverse Portrait
    ' 8 = Reverse Landscape
    ph.SetScreenOrientation(1)
End Sub

You will need to add this line of code where you want to release the screen orientation:

B4X:
PH.SetScreenOrientation(-1)

Or you can use this function created by Stevel05:

http://www.b4x.com/android/forum/threads/freeze-orientation.41681/

There is an error, 0 = Landscape

this is right :

B4X:
Sub Activity_Resume
    ' 1 = Portrait
    ' 0 = Landscape
    ' 9 = Reverse Portrait
    ' 8 = Reverse Landscape
    ph.SetScreenOrientation(1)
End Sub
 
Upvote 0
Top