【问题标题】:Google Maps InfoWindow ImageView谷歌地图信息窗口图像视图
【发布时间】:2015-04-09 18:32:12
【问题描述】:

我正在尝试在 Google Maps v2 的 InfoWindow 中加载动态图像。在从内存加载图像和 getInfoContents 返回要显示的视图之间,我遇到了一个有趣的竞争条件。即使图像在内存中,在位图中,它也可能在返回视图时尚未完成绘制。我在网上尝试了很多解决方案,但没有一个是 100%。

以下是我当前的代码。我覆盖了 GoogleMap.InfoWindowAdapter 的 getInfoContents 方法。

有人知道如何处理这个问题吗?

    @Override
    public View getInfoContents(final Marker marker) {
        final View view = LayoutInflater.from(context).inflate(R.layout.template_map_info_window, null);

        final ImageView vehicleImage = (ImageView) view.findViewById(R.id.infowindow_image);
        vehicleImage.setImageBitmap(myBitmap);

        return view;
    }

【问题讨论】:

    标签: android google-maps infowindow


    【解决方案1】:

    您可以通过here 获得一些想法。

    另外,你可以考虑使用库Picasso

    考虑实现你的图像加载完成的Callback,它将被显示。

    示例代码:

    @Override
            public View getInfoContents(Marker marker) {
    
                ImageView imageView = (ImageView)myContentsView.findViewById(R.id.imgView);
                if (not_first_time_showing_info_window) {
                    Picasso.with(MainActivity.this).load(YOU_IMAGE).into(imageView);
                } else { // if it's the first time, load the image with the callback set
                    not_first_time_showing_info_window=true;
                    Picasso.with(MainActivity.this).load(YOU_IMAGE).into(imageView,new InfoWindowRefresher(marker));
                }
    
                return myContentsView;
            }
    
    private class InfoWindowRefresher implements Callback {
            private Marker markerToRefresh;
    
            private InfoWindowRefresher(Marker markerToRefresh) {
                this.markerToRefresh = markerToRefresh;
            }
    
            @Override
            public void onSuccess() {
                markerToRefresh.showInfoWindow();
            }
    
            @Override
            public void onError() {}
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-10
      • 2013-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多