Android WebView无法加载图片

时间:2016-08-07 09:27:59

标签: android android-webview

<div id="gallery-40" class="gallery galleryid-28208 gallery-columns-2 gallery-size-full">
   <dl class="gallery-item"> 
    <dt class="gallery-icon landscape"> 
     <a href="http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2390.jpg"><img width="1624" height="1080" src="data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=" data-lazy-src="http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2390.jpg" class="attachment-full size-full" alt="androidkosmos_Xiaomi_Max_2390" data-lazy-srcset="http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2390.jpg 1624w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2390-300x200.jpg 300w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2390-1024x681.jpg 1024w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2390-810x539.jpg 810w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2390-50x33.jpg 50w" data-lazy-sizes="(max-width: 1624px) 100vw, 1624px" />
      <noscript>
       <img width="1624" height="1080" src="http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2390.jpg" class="attachment-full size-full" alt="androidkosmos_Xiaomi_Max_2390" srcset="http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2390.jpg 1624w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2390-300x200.jpg 300w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2390-1024x681.jpg 1024w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2390-810x539.jpg 810w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2390-50x33.jpg 50w" sizes="(max-width: 1624px) 100vw, 1624px" />
      </noscript></a> 
    </dt>
   </dl>
   <dl class="gallery-item"> 
    <dt class="gallery-icon landscape"> 
     <a href="http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2396.jpg"><img width="1624" height="1080" src="data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=" data-lazy-src="http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2396.jpg" class="attachment-full size-full" alt="androidkosmos_Xiaomi_Max_2396" data-lazy-srcset="http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2396.jpg 1624w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2396-300x200.jpg 300w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2396-1024x681.jpg 1024w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2396-810x539.jpg 810w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2396-50x33.jpg 50w" data-lazy-sizes="(max-width: 1624px) 100vw, 1624px" />
      <noscript>
       <img width="1624" height="1080" src="http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2396.jpg" class="attachment-full size-full" alt="androidkosmos_Xiaomi_Max_2396" srcset="http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2396.jpg 1624w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2396-300x200.jpg 300w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2396-1024x681.jpg 1024w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2396-810x539.jpg 810w, http://cdn.androidkosmos.de/wp-content/uploads/2016/07/androidkosmos_Xiaomi_Max_2396-50x33.jpg 50w" sizes="(max-width: 1624px) 100vw, 1624px" />
      </noscript></a> 
    </dt>
   </dl>
   <br style="clear: both" /> 
  </div> 

当我将这些数据加载到android WebView时,它不显示图像 内容来自wordpress网站我使用json api获取数据

3 个答案:

答案 0 :(得分:0)

您是否添加了互联网权限?

identifier

将此权限添加到android清单文件中。

它肯定会奏效。

答案 1 :(得分:0)

Android does not support 5.0之前的操作系统版本中的srcset标记。这可能就是为什么noscript中的内容无法加载的原因。对于默认a-href标记中的内容,可能因脚本而无法加载。因此,您需要启用Javascript。

以下代码应启用Javascript(将View ID更改为您的实际WebView):

WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

希望这有帮助。

答案 2 :(得分:0)

您正在尝试加载一堆巨大的图片:img width="1624" height="1080" 对我来说,这似乎有点极端

我将这两个维度除以 4 ,以合理的方式开始 然后可能会调整它们。

Aans还尝试删除所有<noscript />标签(或至少一个,用于测试目的) 看来你需要执行一些服务器脚本来显示图像。