Android Question Issue with .GetContentHeight from the WebviewExtras and WebViewExtras2 library

Seneca

Active Member
Licensed User
Hi,

I have been testing WebViewExtras and WebViewExtras2 to calculate the height of a WV and it occurs to me that the height is calculated correctly only if I execute it in Debug mode and I put a break point in the _pagefinished event (line #36 of the example). In "release" mode it is not calculated correctly.

How can I solve that?

Best regards.

Edit: I had forgotten to attach the file.
 

Attachments

  • Example_height_webview.zip
    8.2 KB · Views: 369
Last edited:

Seneca

Active Member
Licensed User
Hi,

I still can't test this solution because I'm still working with v.6.5

I wanted to learn a little more before making a new subscription. I'll try it soon.

Thanks Erel.
 
Upvote 0

Seneca

Active Member
Licensed User
CallSubUtils isn't an external library, right? It was implemented from version v.6.8

Is this correct?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Seneca

Active Member
Licensed User
Hi,

I'm doing tests using Sleep (with v7.8 Trial) and now I've found a new issue. The height is only calculated correctly if the WV goes from a lower height to a higher height. But on the contrary it doesn't work.

Is it a bug?

Example:

B4X:
Sub Globals
    Dim label1 As Label
    Dim wvinfo As WebView
    Dim wveInfo As WebViewExtras
    Dim infoHTML As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("webview1")
    wveInfo.Initialize (wvinfo)
    infoHTML = "<html><head><style>body {font-size: 18px;}</style></head><body>Initial text. Initial text. Initial text. Initial text.</body></html>"
    wvinfo.LoadHtml(infoHTML)
End Sub

Sub wvinfo_pagefinished (url As String)
    Sleep(100)
    label1.Text = "Height: " & wveInfo.GetContentHeight & " - Scale: " & wveInfo.GetScale
    wvinfo.Height = wveInfo.GetContentHeight * wveInfo.GetScale
End Sub

Sub Font22_Click
    infoHTML = "<html><head><style>body {font-size: 22px;}</style></head><body>In this Case the height of the WV increases. <b>It Is right.</b> In this Case the height of the WV increases. <b>It Is right.</b></body></html>"
    wvinfo.LoadHtml(infoHTML)
End Sub


Sub Font18_Click
    infoHTML = "<html><head><style>body {font-size: 18px;}</style></head><body>In this Case the height of the WV does Not decrease. <b>It Is incorrect.</b> In this Case the height of the WV does Not decrease. <b>It Is incorrect.</b></body></html>"
    wvinfo.LoadHtml(infoHTML)
End Sub
 

Attachments

  • Example_height_webview_2.zip
    8.1 KB · Views: 317
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've changed your code to:
B4X:
Sub Font18_Click
   wvinfo.Height = 20dip
   infoHTML = "<html><head><style>body {font-size: 18px;}</style></head><body>In this Case the height of the WV does Not decrease. <b>It Is incorrect.</b> In this Case the height of the WV does Not decrease. <b>It Is incorrect.</b></body></html>"
   wvinfo.LoadHtml(infoHTML)
End Sub

Seems to work properly.
 
Upvote 0

Seneca

Active Member
Licensed User
Hi,

This solution works, but visually it shows an undesirable effect.

As an alternative, it has occurred to me to use an auxiliary WV (out of the screen) to do the calculation.

B4X:
Sub Globals
    Dim label1 As Label
    Dim wvinfo As WebView
    Dim wvAux As WebView       'Is out of screen
    Dim wveInfo As WebViewExtras
    Dim infoHTML As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("webview1")
    wvAux.Width = wvinfo.Width
    wveInfo.Initialize (wvAux)
    infoHTML = "<html><head><style>body {font-size: 18px;}</style></head><body>Initial text. Initial text. Initial text. Initial text.</body></html>"
    wvAux.LoadHtml(infoHTML)
End Sub

Sub wvAux_pagefinished (url As String)
    Sleep(100)
    label1.Text = "Height: " & wveInfo.GetContentHeight & " - Scale: " & wveInfo.GetScale
    wvinfo.Height = wveInfo.GetContentHeight * wveInfo.GetScale
    wvinfo.LoadHtml(infoHTML)
End Sub

Sub Font22_Click
    infoHTML = "<html><head><style>body {font-size: 22px;}</style></head><body>In this Case the height of the WV increases. <b>It Is right.</b> In this Case the height of the WV increases. <b>It Is right.</b></body></html>"
    wvAux.LoadHtml(infoHTML)
End Sub


Sub Font18_Click
    infoHTML = "<html><head><style>body {font-size: 18px;}</style></head><body>In this Case the height of the WV does Not decrease. <b>It Is incorrect.</b> In this Case the height of the WV does Not decrease. <b>It Is incorrect.</b></body></html>"
    wvAux.LoadHtml(infoHTML)
End Sub
 
Last edited:
Upvote 0
Top