在大多数情况下,Universal Image Loader不显示图像

时间:2013-11-29 19:36:20

标签: java android universal-image-loader

我正在使用通用图片加载器,在我的Google地图上加载自定义信息窗口的图片。但在大多数情况下,它不会加载图像,它显示空图片的图片。

这是我的代码 在MainActivity中:

initImageLoader();      
markers = new Hashtable<String, String>();
imageLoader = ImageLoader.getInstance();

options = new DisplayImageOptions.Builder()
    .showStubImage(R.drawable.loading)        
    .showImageForEmptyUri(R.drawable.empty)   
    .showImageOnFail(R.drawable.error)
    .cacheInMemory(true)
    .cacheOnDisc(true).bitmapConfig(Bitmap.Config.RGB_565)
    .build();

map.setInfoWindowAdapter(new CustomInfoWindowAdapter());              
ReadXML readXml = new ReadXML();
readXml.getXml(camera);

for (int i = 0; i<camera.size(); i++) {
    Camera cam = camera.get(i);
    LatLng coord = new LatLng(cam.lat, cam.lon);

    String title = Integer.toString(cam.id);
    String place = cam.place;
    String url = cam.img;
    Marker mark = map.addMarker(new MarkerOptions()
        .position(coord)
        .title(title)
        .snippet(place)
        .icon(BitmapDescriptorFactory
        .fromResource(R.drawable.green)));              
    markers.put(mark.getId(), url);
}

自定义信息窗口适配器:

 private class CustomInfoWindowAdapter implements InfoWindowAdapter 
{        
    private View view;
    public CustomInfoWindowAdapter() 
    {
        view = getLayoutInflater().inflate(R.layout.custom_info_window,
                null);            
    }

    @Override
    public View getInfoContents(Marker marker) 
    {
        if (MyMapActivity.this.marker != null && MyMapActivity.this.marker.isInfoWindowShown()) 
        {
            MyMapActivity.this.marker.hideInfoWindow();                            
            MyMapActivity.this.marker.showInfoWindow();
        }            
        return null;
    }

    @Override
    public View getInfoWindow(final Marker marker) 
    {
        MyMapActivity.this.marker = marker;
        String url = markers.get(marker.getId());             

        final ImageView image = ((ImageView) view.findViewById(R.id.badge));


        imageLoader.displayImage(url, image, options,
                new SimpleImageLoadingListener() {
            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) 
            {
                super.onLoadingComplete(imageUri, view, loadedImage);
                getInfoContents(marker);
            }
                    });

        final String title = "Камера №" + marker.getTitle();
        final TextView titleUi = ((TextView) view.findViewById(R.id.title));
        if (title != null) {
            titleUi.setText(title);
        } else {
            titleUi.setText("");
        }

        final String snippet = marker.getSnippet();
        final TextView snippetUi = ((TextView) view
                .findViewById(R.id.snippet));
        if (snippet != null) {
            snippetUi.setText(snippet);
        } else {
            snippetUi.setText("");
        } 
        return view;
    }               
}

和Universal Image Loader:

 private void initImageLoader() 
 {
    int memoryCacheSize;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
        int memClass = ((ActivityManager) 
                getSystemService(Context.ACTIVITY_SERVICE))
                .getMemoryClass();
        memoryCacheSize = (memClass / 8) * 1024 * 1024;
    } else {
        memoryCacheSize = 2 * 1024 * 1024;
    }

    final ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
            this).threadPoolSize(5)
            .threadPriority(Thread.NORM_PRIORITY - 2)
            .memoryCacheSize(memoryCacheSize)
            .memoryCache(new FIFOLimitedMemoryCache(memoryCacheSize-1000000))
            .denyCacheImageMultipleSizesInMemory()
            .discCacheFileNameGenerator(new Md5FileNameGenerator())
            .tasksProcessingOrder(QueueProcessingType.LIFO).writeDebugLogs() 
            .build();

    ImageLoader.getInstance().init(config);

}

1 个答案:

答案 0 :(得分:0)

您是否看过以下行实际设置的内容?

String url = markers.get(marker.getId());  

我怀疑这是否像其他谷歌地图实现一样,标记是一个包含多条信息的json字符串/对象,你需要获取它然后从中获取url。尝试并做一些logcat日志记录以确定,你发布了很多代码,所以很难分辨哪些部分是相关的。