Android Code Snippet Set any activity orientation (opposite to #SupportedOrientations)

SubName: Set any activity to the opposite orientation used in the app.
Description: Using this line of code in your manifest allows you to set one (or more) of your projects activities to a different orientation than the default one which is set in the Main activity using #SupportedOrientations.
B4X:
'Set activity to Landscape
SetActivityAttribute(<ActivityName>,
    android:screenOrientation,
    "landscape"
)

Tags: Rotate, Orientation, Activities, Manifest

Please note: I couldn't find this on the forum anywhere, so if it's already on here then I missed it.

Enjoy...
 
Last edited:

Serge Bertet

Active Member
Licensed User
ScreenOrientation possible values: unspecified, landscape, sensorLandscape, sensorPortrait or portrait.
 
Last edited:

Antoine EGO

Member
Thank you Mr. Peter Simpson, for adding this code..
May I have a question?

In My project I have two Activities:
1-Activity "Main" with Landscape orientation. When created it loads layout "frmMain"
2-Layout "Zoom" with Portrait orientation. When created it loads layout "frmZoom"

There is an ImageView in layout "frmMain" showing a scanned document. After clicking on it, layout "frmZoom" is shown with the same document in full screen size.

So, how can I change the orientation from Landscape to Portrait, and back to Landscape again?
Activity "Main":
'Activity "Main"
'---------------
#Region  Project Attributes
    #SupportedOrientations: landscape
#End Region

Sub Process_Globals
    Public MyPhoto As B4XBitmap
End Sub

Sub Globals
    Public imgV As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("frmMain")
    imgV.Bitmap=LoadBitmap(File.DirAssets,"MyScan.jpg")
End Sus

Private Sub imgV_Click
    MyPhoto=imgV.Bitmap
    StartActivity("frmZoom")
End Sub

Activity "Zoom":
'Activity "Zoom"
'---------------
#Region  Activity Attributes
    #FullScreen: True
#End Region

Sub Globals
    Public imgZoom As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("frmZoom")
    imgZoom.Bitmap=Main.MyPhoto
End Sub

Private Sub imgZoom_Click
        StartActivity("frmMain")
End Sub
 
Top