English 中文(简体)
显示网上浏览中预先载录的比照图
原标题:displaying preloaded bitmap in webview

I have a custom ListView that does a lazy load of remote images. When you click a listitem, it starts a new Activity and displays the image in a webview. The problem is, the webview always loads the images, even if the image was preloaded by the listview adapter. I want the WebView to load the image only if it was not preloaded!

这里是我如何把图像上载在清单中:

public void DisplayImage(String url, ImageView imageView)
{
    imageViews.put(imageView, url);
    Bitmap bitmap=memoryCache.get(url);
    if(bitmap!=null)
        imageView.setImageBitmap(bitmap);
    else
    {
        queuePhoto(url, imageView);
        imageView.setImageResource(stub_id);
    }
}

la积图像储存在档案库:

public FileCache(Context context){
    //Find the dir to save cached images
    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
        cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"LazyList");
    else
        cacheDir=context.getCacheDir();
    if(!cacheDir.exists())
        cacheDir.mkdirs();
}

public File getFile(String url){
    //I identify images by hashcode. Not a perfect solution, good for the demo.
    String filename=String.valueOf(url.hashCode());
    //Another possible solution (thanks to grantland)
    //String filename = URLEncoder.encode(url);
    File f = new File(cacheDir, filename);
    return f;

}
最佳回答

处理这一问题的适当方式是安装一个HttpResponseCache,用户/联系人用于下载图像。 尽管平台的安装一直到第13级,但有一个,该版本为Anders 1.5和up服务。 这一ach机制仅适合<代码>Http(s)URLConnection;如果您使用<代码>HttpClient,你将希望阿帕帕奇斯·。 HttpClient Caching Qua

如经快速解决后,你还可以看WebViewClient s shouldRecept(......)quest/code><<><。 如果我不错的话,你可以通过推翻这一方法,拦截一旦某个资源即将解冻时发射的请求,包括图像。 您可以进行一项检查,在当地进行考察,看看是否已经下载图像,如果已经下载的话,则将图像填入<代码>。 Web ResourceResponse。 如果档案是当地提供的,那么就根本不做事,让客户处理下载。 与此相对照的是,网络客户下载的任何东西都不会提供给 la图像装载商。

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签