Android WebView 还是 ImageView?

Android WebView or ImageView?(Android WebView 还是 ImageView?)
本文介绍了Android WebView 还是 ImageView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从 URL 下载和显示图像的应用程序.使用

I have an App that downloads and displays images from URL's. This works fine using

URLConnection conn = urls[i].openConnection();
conn.connect();
if(conn.getContentLength() > 0)
is = conn.getInputStream();
bis = new BufferedInputStream(is);
Bitmap temp = BitmapFactory.decodeStream(bis);

我注意到 WebView 的下载和显示图像比上面的代码快得多,所以我想我会尝试.

I noticed that WebView's download and display images much faster then the above code so I thought i would try.

String url = "http:\image.jpg"
int mWidth = getSystemService(Context.WINDOW_SERVICE).getDefaultDisplay().getWidth()
webView.loadData("<html><body> <img src="" + url + "" width="" + mWidth + "px" height="auto"></body></html>", "text/html", null);

虽然这样可以更快地获取图像,但它不会将图像缩放到屏幕大小,但大图像总是超出 WebView 的宽度,需要滚动才能正确查看.

Although this gets the image much faster it does not scale the image to the size of the screen, the large images always go beyond the WebView's width and require scrolling to view properly.

有谁知道我可以如何解决问题以在 WebView 中正确显示图像,或者首先如何加快图像的下载速度?

Does anyone know how i can fix the issue to display the image properly in the WebView or how to speed up the download of the image in the first place?

我希望加快下载速度,但如果我可以正确缩放图像,我很乐意使用 WebView.

I would prefer to have the download speeded up, but i am happy to use the WebView if i can scale the image correctly.

推荐答案

通过 CSS 设置图片元素的宽度为 100%,高度应根据图片的宽高比缩放.

Set the image elements width to 100% via CSS, height should scale according to the aspect/ratio of the image.

这篇关于Android WebView 还是 ImageView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)