谷歌地图上的自定义信息视图不显示图像

时间:2017-03-20 17:13:25

标签: android google-maps

我从这里开始使用示例代码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;
        }

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

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

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

  

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

如何在InfoView中设置图像?

1 个答案:

答案 0 :(得分:0)

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

相关问题