多个信息窗口的Andr​​oid地图API 2 [英] Multiple Info Windows in Android Maps API 2

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

问题描述

我在写一篇Android的一个基于地图的应用程序中使用地图API V2。

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.

我想我可以写一些code绘制信息窗口以位图支持的画布,并通过这些位图,以地图为标记图标。这种总结了我想要做的相当不错的:我想要的信息窗口的的我的标记。但是,这种方法需要我写我自己的窗框绘图code,我宁愿避免。

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.

所以,不,你不能用常规InfoView的做到这一点,但它不是太难创建作为InfoView的标志。

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>

然后,我把上面这个view成位图并使用该位图作为我的标记:

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();

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

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