如何在Android中使用WebView渲染全分辨率图像?
问题:
我想使用 WebView 在我的应用程序中启用广告的动态加载。我当前正在 HDPI 设备上运行,并且宽度为 480px 的图像被剪切/滚动。如果我使用尺寸为 320 像素的图像,它们会被放大并以过低的分辨率渲染。
加载的 WebView url 的内容是一个简单的网页,只有一个包含在链接中的图像标签,以及一个简单的标题。我尝试过使用视口元标记,但没有任何运气。
有什么建议吗?
The problem:
I want to use a WebView to enable dynamic loading of ads in my app. I'm currently running on a HDPI device, and images width a width of 480px are clipped/scrolled. If I use images with a size of 320px, they are zoomed in and rendered at too low a resolution.
The content of the loaded WebView url is a simple web page with just an image tag wrapped in a link, as well a simple head. I've tried playing with the viewport meta-tag, but without any luck.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我似乎已经解决了。全部解释如下: http://developer.android.com/reference/android/ webkit/WebView.html,在构建网页以支持不同的屏幕密度标题下。不确定当我提出问题时这一部分是否存在,但由于我的问题有一些观点并且没有解决方案,我想我应该将其发布在这里。
Ok, I seem to have worked it out. It's all explained here: http://developer.android.com/reference/android/webkit/WebView.html, under the heading Building web pages to support different screen densities. Not sure if this section was there when I asked the question, but since my question has had a few views and no solution, I thought I'd post it here.
我在网络视图中使用地铁地图图像(1000px,之前也尝试过 3000px 宽度)也遇到了同样的问题:缩放时,图像变得完全模糊,即使原始图形非常清晰且未压缩。
我发现的唯一方法是将图像分成多个切片,然后通过 html 表将它们重新组合在一起。这样,变焦时仍能保持清晰度。
不确定您使用的是哪种设备,但 Nexus One 普遍存在一些显示问题,例如: http://www.displaymate.com/Nexus_One_ShootOut.htm
I had the same issue with a subway map image (1000px, also tried 3000 px width before) in a webview: when zooming, the image gets totally blurry, even though the original graphic is very sharp and uncompressed.
The only way I found is to split the images into multiple slices and put them back together via html table. This way, the sharpness remains when zooming.
Not sure, which device you're on, but there are i.e. some display issues in general with the Nexus One for example: http://www.displaymate.com/Nexus_One_ShootOut.htm