Android Maps API 2中的多資訊視窗
我正在使用Maps API v2在Android上編寫一個基於地圖的應用.
我已經將標記放在地圖上,並可以顯示這些標記的自定義資訊視窗,但是AFAICT一次只能顯示一個資訊視窗.有幾個點,我想要不同的行為:我想總是顯示多個視窗的資訊視窗,沒有標記顯示.
我想我可以編寫一些程式碼來繪製資訊視窗到點陣圖支援的畫布,並將這些點陣圖作為標記“圖示”傳遞給地圖.這種總結我正在努力做的很好:我希望資訊視窗成為我的標記.但是這種方法需要我寫我自己的窗框繪圖程式碼,我寧願避免.
是否有更好的方式支援一次顯示多個資訊視窗?
在文件中它指出:
Since there is only one info window shown at any one time, thisprovider may choose to reuse views, or it may choose to create newviews on each method invocation.
所以沒有你不能用常規的infoviews做,但它不是太難建立標記作為infoviews.
編輯
我將在xml中建立一個要用作標記/對話方塊的檢視.這樣的事情
<?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>
然後我會將此檢視轉換為點陣圖,並將該點陣圖用作我的標記:
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();
http://stackoverflow.com/questions/15331983/multiple-info-windows-in-android-maps-api-2