如何使用标记(1,2,3 ...)中的数字和InfoWindow中的展开按钮创建自定义Android标记? 据我所知,第一个问题我可以用.icon解决
//add marker to Map
mMap.addMarker(new MarkerOptions().position(USER_POSITION)
.icon(BitmapDescriptorFactory.fromBitmap(bmp))//my image here
// Specifies the anchor to be at a particular point in the marker image.
.anchor(0.5f, 1));
但InfoWindow呢?如何添加到它按钮,弹出大的InfoWindow?
答案 0 :(得分:2)
这样做就是这样......
googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker marker) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker marker) {
// Getting view from the layout file info_window_layout
View v = getLayoutInflater().inflate(R.layout.info_window_layout, null);
// Getting reference to the TextView to set title
TextView note = (TextView) v.findViewById(R.id.note);
note.setText(marker.getTitle() );
// Returning the view containing InfoWindow contents
return v;
}
});
只需在您使用GoogleMap的班级中添加上述代码即可。 R.layout.info_window_layout是我们的自定义布局,显示将取代infowindow的视图。我刚刚在这里添加了textview。您可以在此处添加额外视图,使其像示例快照一样。我的info_window_layout是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/note"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>