我的地图窗口信息有一个自定义布局,但我看不到任何关于如何从标记传递数据的示例。
有人可以帮忙吗?
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker arg0) {
View v = getActivity().getLayoutInflater().inflate(R.layout.info_window_layout, null);
ImageView pic = (ImageView) v.findViewById(R.id.pic);
String url = <????>;
// set pic image from url
TextView name = (TextView) v.findViewById(R.id.name);
name.setText(<????>);
TextView address = (TextView) v.findViewById(R.id.address);
address.setText(<????>);
return v;
}
});
mCenterList = MyApplication.dbHelper.getAllCenter();
for(Center center : mCenterList){
Marker marker = mMap.addMarker(
new MarkerOptions().position(new LatLng(center.lat, center.lng))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.elipin)));
// How can I pass custom data, here pic, name and address, to the marker, to
// make it available in getInfoContents?
}
info_window_layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="300dp"
android:layout_height="50dp"
android:padding="5dp" >
<ImageView
android:id="@+id/pic"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginRight="5dp"
android:scaleType="centerCrop" />
<ImageView
android:id="@+id/arrow"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="5dp"
android:scaleType="centerCrop"
android:src="@drawable/arrowri" />
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_toRightOf="@id/pic"
android:layout_toLeftOf="@id/arrow"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="#ffffff"
android:textSize="18sp" />
<TextView
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="15dp"
android:layout_toRightOf="@id/pic"
android:layout_toLeftOf="@id/arrow"
android:layout_below="@id/name"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="#ffffff"
android:textSize="16sp" />
</RelativeLayout>