Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put drawable as a background on InfoWindow (Google Maps API v2 for Android)?

Tags:

This is my custom layout for my info window:

<RelativeLayout          xmlns:android="http://schemas.android.com/apk/res/android"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:background="@drawable/bg_infowindow" >     <LinearLayout             android:id="@+id/text_box"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:orientation="vertical" >         <TextView              style="@style/TexTitle"             android:id="@+id/title"             android:layout_width="wrap_content"             android:layout_height="wrap_content" />     <TextView              style="@style/TextDistance"             android:id="@+id/distance"             android:layout_width="wrap_content"             android:layout_height="wrap_content" />     </LinearLayout> </RelativeLayout> 

And this is my custom adapter:

public class MapInfoWindowAdapter implements InfoWindowAdapter{      private LayoutInflater inflater;     private Context context;      public MapInfoWindowAdapter(Context context){         inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );         this.context = context;     }      @Override     public View getInfoContents(Marker marker) {          // Getting view from the layout file         View v = inflater.inflate(R.layout.map_popup, null);          TextView title = (TextView) v.findViewById(R.id.title);         title.setText(marker.getTitle());          TextView address = (TextView) v.findViewById(R.id.distance);         address.setText(marker.getSnippet());          return v;     }      @Override     public View getInfoWindow(Marker arg0) {         // TODO Auto-generated method stub         return null;     }  } 

And this is the result:

enter image description here

However I want the custom drawable as the only background for my info window, How to achieve this?

like image 843
IsaacCisneros Avatar asked May 13 '13 09:05

IsaacCisneros


People also ask

How do I put InfoWindow on marker?

Call setPosition() on the info window, or. Attach the info window to a new marker using the InfoWindow. open() method. Note: If you call open() without passing a marker, the InfoWindow will use the position specified upon construction through the InfoWindowOptions object literal.

How do I change the width of InfoWindow on Google Maps?

maps. InfoWindow({ content: some_text, maxWidth: 200 }); The documentation notes that the "value is only considered if it is set before a call to open. To change the maximum width when changing content, call close, setOptions, and then open."


1 Answers

Replace codes in getInfoContents with getInfoWindow. The difference between them is getInfoContents wraps your View in ViewGroup with default background.

@Override public View getInfoWindow(Marker marker) {      // Getting view from the layout file     View v = inflater.inflate(R.layout.map_popup, null);      TextView title = (TextView) v.findViewById(R.id.title);     title.setText(marker.getTitle());      TextView address = (TextView) v.findViewById(R.id.distance);     address.setText(marker.getSnippet());      return v; }  @Override public View getInfoContents(Marker arg0) {     // TODO Auto-generated method stub     return null; } 
like image 72
MaciejGórski Avatar answered Oct 19 '22 06:10

MaciejGórski