Hi, I'm trying to change the dimension of the webview through screen orientation without making the stream in webview to stop.
Erel wrote this code in 2016:
Add this line to the manifest editor:
but he also said:
So I tried as he stated to
and to be honest, this latter didn't help me out.
I wonder if 6 year after there is a solution..
This is a video of how my app is working
As you can see the layout is being created with the WebView at the top, then I rotate the screen in landscape fullscreen ( even though it is not possible to see through the video..) and the again at portrait, but the webview doesn't come back to the original position at the top and as you can see, it stays inside the "fullscreen mode"...
Another code I'm trying is this one ( which works for changing rotation, but I still can't find the right sizes)
it works on portrait, but on fullscreen landscape
Is there a way to fix it? Thanks
Erel wrote this code in 2016:
Add this line to the manifest editor:
B4X:
SetActivityAttribute(Main, android:configChanges, "orientation|screenSize")
B4X:
Sub Globals
Private ime1 As IME
Private WebView1 As WebView
Private ActivityParent As JavaObject
End Sub
Sub Activity_Create(FirstTime As Boolean)
WebView1.Initialize("WebView1")
Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
ime1.Initialize("ime1")
ime1.AddHeightChangedEvent
WebView1.LoadUrl("http://www.google.com")
Dim jo As JavaObject = Activity
jo.RunMethodJO("getContext", Null).RunMethodJO("getWindow", Null).RunMethod("setSoftInputMode", _
Array As Object(0x20))
ActivityParent = jo.RunMethodJO("getParent", Null)
End Sub
Sub IME1_HeightChanged (NewHeight As Int, OldHeight As Int)
CallSubDelayed(Me, "AfterChange")
End Sub
Sub AfterChange
Dim ajo As Panel = Activity
Dim width As Int = ActivityParent.RunMethod("getMeasuredWidth", Null)
Dim height As Int = ActivityParent.RunMethod("getMeasuredHeight", Null)
If width = 0 OR height = 0 Then Return
ajo.Width = width 'update the "activity" width and height
ajo.Height = height
WebView1.Width = width
WebView1.Height = height
End Sub
Sub Activity_Resume
AfterChange
End Sub
but he also said:
becauseI don't recommend using the solution in this thread unless it is critical that the WebView will not be reloaded. It breaks that standard program flow as the Activity is not recreated as it should be.
you will need to manually update the layout. Another possible solution is to lock this specific activity orientation.
So I tried as he stated to
update the layout in AfterChange sub. Call Activity.RemoveAllViews before you load the new layout.
and to be honest, this latter didn't help me out.
I wonder if 6 year after there is a solution..
This is a video of how my app is working
As you can see the layout is being created with the WebView at the top, then I rotate the screen in landscape fullscreen ( even though it is not possible to see through the video..) and the again at portrait, but the webview doesn't come back to the original position at the top and as you can see, it stays inside the "fullscreen mode"...
Another code I'm trying is this one ( which works for changing rotation, but I still can't find the right sizes)
B4X:
Private screenwidth As Int = GetDeviceLayoutValues.Width
Private screenheight As Int = GetDeviceLayoutValues.Height
Private left As Int = (screenwidth/2)-(WebView1.Width/2)
Private top As Int = (screenheight/2)-(WebView1.height/2) -40
If (screenwidth < screenheight) Then ' portrait
WebView1.SetLayout(0dip,0dip,WebView1.width,WebView1.height)
Else
WebView1.SetLayout(left, top, screenwidth,screenheight)
End If
it works on portrait, but on fullscreen landscape
Is there a way to fix it? Thanks
Last edited: