1

I have placed the map fragment inside a LinearLayout which is a child of a ScrollView. When I encounter the map as I scroll down, the map leaves a black patch on the screen. I am facing this issue in devices before ICS viz. Gingerbread. Has anyone faced a similar issue ?enter image description here

Shishir Shetty
  • 2,021
  • 3
  • 20
  • 35
  • 1
    possible duplicate http://stackoverflow.com/questions/13793483/google-maps-android-api-v2-blacking-out-part-of-layout?rq=1 – chopchop May 16 '13 at 10:11
  • 1
    and this: http://stackoverflow.com/questions/16017498/slidingmenu-shows-blsck-when-used-with-map-api-v2 – MaciejGórski May 16 '13 at 10:15

1 Answers1

1

I got the solution !!

Create a class MyMapFragment

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.gms.maps.SupportMapFragment;

public class MyMapFragment extends SupportMapFragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        setMapTransparent((ViewGroup) view);
        return view;
    };

    private void setMapTransparent(ViewGroup group) {
        int childCount = group.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = group.getChildAt(i);
            if (child instanceof ViewGroup) {
                setMapTransparent((ViewGroup) child);
            } else if (child instanceof SurfaceView) {
                child.setBackgroundColor(0x00000000);
            }
        }
    }
}

Initialize GoogleMap

map = ((MyMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.mapView)).getMap();

inside xml

<LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="250dp"
            android:layout_marginBottom="15dp"
            android:background="@drawable/mapouter" >

            <fragment
                xmlns:map="http://schemas.android.com/apk/res-auto"
                android:id="@+id/mapView"
                android:name="com.example.MyMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </LinearLayout>
Shishir Shetty
  • 2,021
  • 3
  • 20
  • 35