How to display a photo in the center of WebView?

wy328

Member
Licensed User
Longtime User
I've tried following code with no lcuk:
wView.LoadHtml("<div style='height:500px;background:#FFFFFF;margin 0:auto;'><table height=100% width=100%><tr valign='middle' align='center'><td><img align='absmiddle' src='File:///" & filePath & "'/></td></tr></table></div>")

anyone could help me please? :sign0085:
 

susu

Well-Known Member
Licensed User
Longtime User
Try this code:

WebView.LoadHtml("<html><head><style Type=""text/css""> img { position: absolute; width: 300px; height: 300px; left: 50%; top: 50%; margin-left: -150px; margin-top: -150px; }</style> </head> <body> <img src=""File:///android_asset/picture.png""> </body> </html>")

Remember to change your picture's width/height and margin-left is picture width/2 and margin-top is picture height/2.
 
Upvote 0

merlin2049er

Well-Known Member
Licensed User
Longtime User
ok, that's awesome. How would you pass a string to webview html page. I guess I can design the page in an html editor, then just substitute some variables.
 
Upvote 0
Top