相关疑难解决方法(0)

Android WebView还是ImageView?

我有一个应用程序,可以下载并显示来自URL的图像.这很好用

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

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

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);
Run Code Online (Sandbox Code Playgroud)

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

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

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

android download scale webview imageview

2
推荐指数
1
解决办法
2629
查看次数

标签 统计

android ×1

download ×1

imageview ×1

scale ×1

webview ×1