Eloi Navarro
Eloi Navarro

Reputation: 1445

SupportMapFragment in Nexus One

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 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:

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.

Upvotes: 1

Views: 872

Answers (2)

Tspoon
Tspoon

Reputation: 3800

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

Upvotes: 0

Robert Estivill
Robert Estivill

Reputation: 12497

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

Upvotes: 4

Related Questions