Question

I'm having some problems mixing the old Google Nexus One with the new SupportMapFragment.

In a particular landscape view I have an HorizontalScrollView with a map and some info in a way you have to scroll in order to actually see the info.

The problem is that scrolling makes (somehow I can't understand right now) the SupportMapFragment's background visible (which seems to be black by default) while actually scrolling the whole view

Picture to show what I mean.

Behaviour demo

Altough not the same exact issue, there is a similar, reported bug, about it in gmaps-api-issues


So, what I've tested so far:

  • Setting the background to @color/transparent, even in XML and/or programatically.
  • Changing the SupportMapFragment z-ordering

Setting this code before calling my map:

GoogleMapOptions op = new GoogleMapOptions();
op.zOrderOnTop(true);
SupportMapFragment.newInstance(op);

So I ran out of ideas. I've successfully tested same exact code in:

  • Galaxy Nexus
  • HTC Desire HD
  • Samsung Galaxy S3
  • Samsung Galaxy Mini
  • Galaxy Ace

EDIT: An interesting thing is, taking the screenshot made me realize that it was imposible to capture my specific case. When the screenshot was taken, the error only could be reproduced by changing to portrait and landscape again.

Any ideas? Did I missed anything obvious?

Thanks in advance for your comments.

Was it helpful?

Solution

I had a very similar issue but when i was adding the SlidingMenu library and i fixed it by using the hack on this comment

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);
       }
   }
 }

OTHER TIPS

Just to add to Robert Estivill's answer - it's probably best not to run the code on devices >= 4.1, as there is no problem with them.

Slightly modified version:

public class FixMapFragment extends SupportMapFragment {

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

        // Fix for black background on devices < 4.1
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN){
            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);
            }
        }
    }
}

I would have put this in a comment, but I don't have enough rep

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top