Webview not the same on different screen solution?

susu

Well-Known Member
Licensed User
Longtime User
I'm using WebView to show an image and I want it "fit" the screen. This is my code

B4X:
Dim PZW As WebView
Dim ww As Int

PZW.Initialize("PZW")
Activity.AddView(PZW, 0, 0, 100%x, 100%y)

If Activity.Width > Activity.Height Then
   ww = Activity.Height
Else
   ww = Activity.Width
End If

PZW.LoadHtml("<html><body topmargin='0' leftmargin='0' marginwidth='0' marginheight='0'><center><img src='file:///android_asset/testimage.jpg' width='" & ww &"'/></center></body></html>")

It works ok on small screen (320x480) but on bigger screen (480x800) it only shows half of image. Please view the attached files. I don't understand what's wrong here?

attachment.php


attachment.php
 

Attachments

  • 320x480.jpg
    320x480.jpg
    92.6 KB · Views: 557
  • 480x800.jpg
    480x800.jpg
    83.2 KB · Views: 580

NJDude

Expert
Licensed User
Longtime User
If you want to fit the picture then you have to do this:

B4X:
PZW.LoadHtml("<html><body topmargin='0' leftmargin='0' marginwidth='0' marginheight='0'><center><img src='file:///android_asset/samplepic.jpg' width='100%' height='100%'/></center></body></html>")

That will fit the picture to the size of the WebView and NOT the Activity as you have it on your code.
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
Upvote 0
Top