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

后端 未结 3 1625
日久生厌
日久生厌 2020-12-14 18:16

This is my custom layout for my info window:



        
相关标签:
3条回答
  • 2020-12-14 18:48

    try this..

    custom_infowindow.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    
    
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#80000000" 
    android:orientation="vertical">
    
    <ImageView
        android:src="@drawable/ic_launcher"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:padding="10dp"/>
    
    </LinearLayout> 
    
    </LinearLayout>
    
    
    googleMap.setInfoWindowAdapter(new InfoWindowAdapter() 
    {
    
            public View getInfoWindow(Marker arg0)
            {
                View v = getLayoutInflater().inflate(R.layout.custom_infowindow, null);
                return v;
            }
    
            public View getInfoContents(Marker arg0) 
            {
               return null;
            }
        });
    
    0 讨论(0)
  • 2020-12-14 18:59

    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;
    }
    
    0 讨论(0)
  • 2020-12-14 18:59

    in addition to the accepted answer i want to mention that if you still want the info window bubble you can use this bubble layout library

    then you can set the bubble layout as background of your route view in the custom layout you are inflating.

    0 讨论(0)
提交回复
热议问题