【问题标题】:Custom info view on google map does not show the image谷歌地图上的自定义信息视图不显示图像
【发布时间】:2017-03-21 02:44:25
【问题描述】:

我从这里开始使用示例代码 CurrentPlaceDetailsOnMap: CurrentPlaceDetailsOnMap

我更改了它,将图像添加到信息视图。然后我尝试在 getInfoContents 中加载图像

        @Override
        public View getInfoContents(final Marker marker) {
            // Inflate the layouts for the info window, title and snippet.
            View infoWindow = getLayoutInflater().inflate(R.layout.custom_info_contents, (FrameLayout)findViewById(R.id.map), false);

            TextView title = ((TextView) infoWindow.findViewById(R.id.title));
            title.setText(marker.getTitle());

            TextView snippet = ((TextView) infoWindow.findViewById(R.id.snippet));
            snippet.setText(marker.getSnippet());
            final ImageView imageView = ((ImageView) infoWindow.findViewById(R.id.image));

            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    Bitmap bitmap = getBitmap(MapsActivityCurrentPlace.this, R.drawable.my_bitmap;
                    imageView.setImageBitmap(bitmap);
                }
            });

            return infoWindow;
        }

在上面的代码中,我使用Handleronly 来模拟当我通过调用Places.GeoDataApi.getPlacePhotos 异步加载图像时会发生什么。 结果是图像未显示。 如果我打电话:

                    Bitmap bitmap = getBitmap(MapsActivityCurrentPlace.this, R.drawable.my_bitmap;
                    imageView.setImageBitmap(bitmap);

同步一切都很好。 看起来谷歌地图缓存了视图,创建了整个视图的图像。来自文档:

注意:绘制的信息窗口不是实时视图。视图在返回时呈现为图像(使用 View.draw(Canvas))。这意味着对视图的任何后续更改都不会反映在地图上的信息窗口中。要稍后更新信息窗口(例如,加载图像后),请调用 showInfoWindow()。此外,信息窗口不会尊重任何普通视图的典型交互性,例如触摸或手势事件。但是,您可以在整个信息窗口上收听通用点击事件,如下节所述。

如何在 InfoView 中设置图像?

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    目前我找到的唯一解决方案是提前加载位图并将其存储在缓存中,然后将位图同步分配给 infoview.imageView。 但这意味着我必须提前加载图像。

    【讨论】:

      猜你喜欢
      • 2013-02-16
      • 2015-04-09
      • 1970-01-01
      • 1970-01-01
      • 2016-12-21
      • 1970-01-01
      • 2013-05-20
      • 2016-01-26
      • 2019-05-17
      相关资源
      最近更新 更多