Multiple Info Windows in Android Maps API 2

后端 未结 1 1205
死守一世寂寞
死守一世寂寞 2020-12-03 07:32

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

I already have markers being placed on the map, and can display custom info windows for those markers, but

相关标签:
1条回答
  • 2020-12-03 08:19

    In the docs it states:

    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.

    Edit

    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();
    
    0 讨论(0)
提交回复
热议问题