Android Webview 图像渲染到中心而不是左上角

标签 android webview

webview 中的图像渲染从我的图像的左上角开始,它比 webview 大,所以它可以滚动。我想让图像居中而不是渲染到左上角...有什么办法可以做到这一点吗?

最佳答案

代替调用 myWebView.loadUrl,您可以使用纯 CSS 并调用 myWebView.loadData。

只需确保对任何无关字符进行 URL 编码。 示例:

myWebView.loadData("<html><head><style type='text/css'>body{margin:auto auto;text-align:center;} img{width:100%25;} </style></head><body><img src='www.mysite.com/myimg.jpeg'/></body></html>" ,"text/html",  "UTF-8");

关于Android Webview 图像渲染到中心而不是左上角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7516623/

相关文章:

java - 如何从连接到 Android 设备的串行 GPS 获取数据?

android - WebView 和 HTTPClient 之间共享 Cookies?

android - Android 的 Crashwrangler 或 !exploitable 等价物

android - 如何在 Mac、Windows 和 Linux 中使用 keytool 为默认调试 key 生成 SHA1、SHA256、MD5?

android - 如何仅在最顶部的 fragment 上触发 onResume(),在后退时

android - Phonegap + SSL + iPhone

ios - 嵌入 Youtube 视频显示黑屏

android - 应用 WebView 中的 OTP 检测

objective-c - 如何验证给定时间WebView是否执行JS代码?

ios - 无法在 iOS Appium 测试 (AWS Device Farm) 上切换到 WebView 上下文