Android WebView or 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="IiArIHVybCArIA=="" 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android WebView 还是 ImageView?
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01