Android Maps API 2 中的多个信息窗口 [英] Multiple Info Windows in Android Maps API 2

查看:28
本文介绍了Android Maps API 2 中的多个信息窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Maps API v2 在 Android 上编写基于地图的应用.

I'm writing a map-based app on Android using Maps API v2.

我已经在地图上放置了标记,并且可以为这些标记显示自定义信息窗口,但 AFAICT 一次只能显示一个信息窗口.有几个地方我想要不同的行为:我希望始终显示多个窗口的信息窗口,而不显示标记.

I already have markers being placed on the map, and can display custom info windows for those markers, but AFAICT only one info window can be displayed at a time. There are a couple of spots where I want different behaviour: I want to always display the info window for multiple windows, without a marker showing.

我想我可以编写一些代码来将信息窗口绘制到位图支持的画布上,并将这些位图作为标记图标"传递给地图.这总结了我正在努力做的事情:我希望信息窗口成为我的标记.但是这种方法需要我编写自己的窗口框架绘制代码,而我宁愿避免这种代码.

I suppose I could write some code to draw the info windows to bitmap-backed canvases and pass those bitmaps to the map as marker "icons". This kind of sums up what I'm trying to do quite well: I want the info windows to be my markers. But this approach would require me to write my own window frame drawing code which I'd rather avoid.

是否有更好的方法支持一次显示多个信息窗口?

Is there a better way of supporting more than one info window being displayed at once?

推荐答案

在文档中说明:

由于在任何时候都只显示一个信息窗口,因此提供者可以选择重用视图,也可以选择创建新的对每个方法调用的看法.

Since there is only one info window shown at any one time, this provider may choose to reuse views, or it may choose to create new views on each method invocation.

所以不,你不能用常规的信息视图来做到这一点,但创建充当信息视图的标记并不太难.

So no you can't do it with the regular infoviews but it isn't too hard creating markers that act as infoviews.

编辑

我会在 xml 中创建一个您想用作标记/对话框的视图.像这样:

I'd create a view in xml that you want to use as a marker/dialog. Something like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:orientation="vertical"
    android:background="@android:color/white"
    >
    <TextView
        android:text="test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <ImageView 
        android:src="@drawable/ic_launcher"
        android:layout_width="50dp"
        android:layout_height="50dp"/>
</LinearLayout>

然后我将此视图转换为位图并使用该位图作为我的标记:

Then I'd convert this view into a bitmap and use that bitmap as my marker:

        ImageView image = (ImageView) findViewById(R.id.main_image);

        LinearLayout tv = (LinearLayout) this.getLayoutInflater().inflate(R.layout.test_layout, null, false);
        tv.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight()); 

        tv.setDrawingCacheEnabled(true);
        tv.buildDrawingCache();
        Bitmap bm = tv.getDrawingCache();

这篇关于Android Maps API 2 中的多个信息窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆