简体   繁体   English

Android缓存Webview图像?

[英]Android cache webview images?

I've Listview activity each row content webview and the webview content article html code with images. 我已经进行了Listview活动,每行内容都有webviewwebview内容带有图像的html代码。

So far everything is perfect, but my problem is if the listview scrolled the webview lost images and reopen them again, and the listview become crazy. 到目前为止,一切都很完美,但是我的问题是,如果listview滚动了webview丢失的图像并再次将其重新打开,则listview变得很疯狂。

I want to cache webview images to prevent it to reopen or download the images again. 我想缓存webview图像以防止其重新打开或再次下载图像。 How? 怎么样?

I am new in Android and sorry for my English. 我是Android新手,对不起我的英语。

Any advice? 有什么建议吗?

This is my webview settings: 这是我的网络视图设置:

    holder.message.addJavascriptInterface(new test_js(context), "Android");
    holder.message.getSettings().setJavaScriptEnabled(true);
   // holder.message.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
    holder.message.getSettings().setTextSize(WebSettings.TextSize.NORMAL);          

    //test
    holder.message.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    holder.message.getSettings().setAppCacheMaxSize( 8 * 1024 * 1024 ); // 8MB
    holder.message.getSettings().setAppCachePath(context.getApplicationContext().getCacheDir().getAbsolutePath());
    holder.message.getSettings().setAllowFileAccess(true);
    holder.message.getSettings().setAppCacheEnabled(true);

but it won't cache the images it's redownloading them again when I scroll the listview! 但它不会缓存图像,因此当我滚动列表视图时会重新下载它们!

I recommend you to use Universal-Image-Loader for loading and caching images when working with listview or recyclerview . 我建议您在使用listviewrecyclerview时,使用Universal-Image-Loader加载和缓存图像。 The Universal-Image-Loader has option delayBeforeLoading(time) to prevent listview's scroll issues when there is item with images. Universal-Image-Loader具有选项delayBeforeLoading(time)以防止在有图像项时listview的scroll问题。 And to cache other content just write the body of response to file and extract it to your listview. 要缓存其他内容,只需将响应正文写入文件并将其提取到列表视图即可。

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

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