简体   繁体   English

在Android WebView中加载图像的好方法是什么?

[英]What is a good way to load images in Android WebView?

Premise 前提

  1. My WebView have many images,Like news app. 我的WebView有很多图像,例如新闻应用程序。
  2. WebView build by Stitching body from server with my local html template. 通过使用我的本地html模板从服务器缝合主体来构建WebView。
  3. If i wait webView when it onProgressChanged() newProgress == 100 ,then show it for user, it will wait lots of time, and when network is not good, this experience was to terrible 如果我在webView上onProgressChanged() newProgress == 100时等待它,然后向用户显示它,它将等待很多时间,并且当网络不好时,这种体验太糟糕了
  4. So, i want know if has a good way to load images ? 所以,我想知道是否有加载图像的好方法?

Two way i know 我知道的两种方式

  1. Image not display immediately, and when i slide the page image start cache and display 图像无法立即显示,并且当我滑动页面图像时,开始缓存并显示
  2. Or another way, just display text and image display placeholder with local for user, and i start a Thread to cache images on backGround, when images cache finish to replace placeholder 或以另一种方式,只显示文本和图像显示占位符以及本地用户,当图像缓存完成替换占位符时,我启动一个线程在backGround上缓存图像

What is a good way to load images in Android WebView ? 在Android WebView中加载图像的好方法是什么?

Please Thanks ! 请谢谢!

One of the most famous way to load images from any source into the app is by using an image loading library called Glide . 从任何来源将图像加载到应用程序中,最著名的方法之一是使用名为Glide的图像加载库。

Follow the setup steps to get started. 请按照设置步骤开始。 In the activity that you want an image to be loaded, declare an ImageView variable and use 在要加载图像的活动中,声明一个ImageView变量并使用

ImageView imej = (ImageView) findViewById (R.id.imageID);
Glide.with(this).load("URL").into(imej);

If you wish to use the cache capabilities, add 如果您希望使用缓存功能,请添加

.diskCacheStrategy(DiskCacheStrategy.SOURCE*)

between the .load() and .into() methods. 在.load()和.into()方法之间。 Note that DiskCacheStrategy has 4 types. 请注意,DiskCacheStrategy具有4种类型。 Choose wisely. 做出明智的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM