Ranjith
Ranjith

Reputation: 343

Custom info window in android map v2

I am trying to develop a custom info window in android map v2.I want to know how to remove the white background from the info window and how to set the background outside the circle radius to transparent blackenter image description here

This is the xml for my custom info window

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/dp"
    android:orientation="vertical">



</LinearLayout>

This is my code to make a custom info window

 getMap().getMap().setInfoWindowAdapter(new InfoWindowAdapter() {

                @Override
                public View getInfoWindow(Marker arg0) {
                    // TODO Auto-generated method stub
                    return null;
                }

                @Override
                public View getInfoContents(Marker arg0) {
                    // TODO Auto-generated method stub
                    // Getting view from the layout file info_window_layout
                    View v = getLayoutInflater().inflate(R.layout.windowlayout,
                            null);

                    return v;
                }
            });
private SupportMapFragment getMap() {
        return ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map));
    }

This is my marker click

@Override
    public void onMapClick(LatLng point) {
        // TODO Auto-generated method stub
        Toast.makeText(getApplicationContext(), point.toString(),
                Toast.LENGTH_SHORT).show();
        getMap().getMap().animateCamera(CameraUpdateFactory.newLatLng(point));
        CameraUpdate zoom = CameraUpdateFactory.zoomTo(8);

        getMap().getMap().moveCamera(CameraUpdateFactory.newLatLng(point));
        getMap().getMap().animateCamera(zoom);
        Marker marker;
        getMap().getMap().clear();
        marker = getMap().getMap().addMarker(
                new MarkerOptions()
                        .draggable(true)
                        .position(point)
                        .title("Pick Up")
                        .icon(BitmapDescriptorFactory
                                .fromResource(R.drawable.marker)));

        // marker.setPosition(point);
        marker.showInfoWindow();
        rl.setVisibility(View.VISIBLE);
    }

This is my map layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/data"
        android:layout_alignParentTop="true" >

        <fragment
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.muratonnet.map.TouchableSupportMapFragment" />

        <RelativeLayout
            android:id="@+id/rl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/circle"
            android:layout_gravity="center"
            android:visibility="gone" >
        </RelativeLayout>
    </FrameLayout>

    <LinearLayout
        android:id="@+id/data"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <include layout="@layout/data_table" />
    </LinearLayout>

</RelativeLayout>

Upvotes: 2

Views: 3875

Answers (1)

Manoj Srivastava
Manoj Srivastava

Reputation: 670

Please set your infowindow view at getInfoWindow() not getInfoContents();

By this you can remove default background of infoWindow.

So you have to inflate your view like this :

getMap().setInfoWindowAdapter(new InfoWindowAdapter() {

                @Override
                public View getInfoWindow(Marker arg0) {
                    // TODO Auto-generated method stub
                    // Getting view from the layout file info_window_layout
                    View v = getLayoutInflater().inflate(R.layout.windowlayout,
                            null);

                    return v;
                }

                @Override
                public View getInfoContents(Marker arg0) {
                    return null;
                }
            });
private SupportMapFragment getMap() {
        return ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map));
    }

Upvotes: 7

Related Questions