问题
Can we make Custom MarkerOptions in google?
I want to use Custom MarkerOptions to show image in Dialog box like Containng Name as title, and two image within it.
<ImageView
android:id="@+id/badge"
android:layout_width="18dp"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:src="@drawable/image_2"
android:adjustViewBounds="true"></ImageView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ellipsize="end"
android:text="harish"
android:singleLine="true"
android:textColor="#ff000000"
android:textSize="7dp"
android:textStyle="bold" />
<ImageView
android:id="@+id/snippet"
android:layout_width="10dp"
android:layout_height="10dp"
android:ellipsize="end"
android:src="@drawable/icon_location2"
android:singleLine="true"
android:textColor="#ff7f7f7f"
android:textSize="14dp" />
</LinearLayout>
With default MarkerOption i can only get Title , Snippet in dialog box like this:
public void addMarkersToMap() {
mArun = mMap.addMarker(new MarkerOptions()
.position(ARUN)
.title("Arun")
.snippet("Match stat:")
.icon(BitmapDescriptorFactory.defaultMarker
(BitmapDescriptorFactory.HUE_AZURE)));
help me with some suggestion .
回答1:
You will have to use the setInfoWindowAdapter
method of GoogleMap
class.
GoogleMap mMap;//You have to initialise it.
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
/*
Here you will inflate the custom layout that you want to use for marker. I have inflate the custom view according to my requirements.
*/
View v = getLayoutInflater().inflate(R.layout.custom_marker_info_window, null);
TextView textView = (TextView) v.findViewById(R.id.text);
textView.setSelected(true);
textView.setText(poiPlayerData.getName());
return v;
}
});
来源:https://stackoverflow.com/questions/40873209/custom-marker-options-in-google-map