Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work well with Google Map v2 (SupportMapFragment) #168

Closed
avatar21 opened this issue Dec 6, 2012 · 38 comments
Closed

Doesn't work well with Google Map v2 (SupportMapFragment) #168

avatar21 opened this issue Dec 6, 2012 · 38 comments

Comments

@avatar21
Copy link

avatar21 commented Dec 6, 2012

I liked your work, it works great without a map fragment ... since MapFragment came out from Google not long ago, I've tried to look for ways to integrate SherlockActionbar + SlidingMenu + MapFragment ...

The result:

  • No error, but there's a shadow (think is OpenGL issue left behind by MapFragment) on top of the behindContentView when I slide ... Please kindly help ...

Note: I think this is related to issue #62

References:
http://facebook.stackoverflow.com/questions/13721929/using-actionbarsherlock-with-the-new-supportmapfragment/13727539#13727539

public class SlideExample extends SlidingFragmentActivity {

public void onCreate(Bundle savedInstanceState) {
// ...
setContentView(R.layout.view_with_map_fragment);
// ...

Screenshot:

Hardware:

  • running on Sony Ericsson Xperia Play (Android 2.3.6)
@aeroperf
Copy link

aeroperf commented Dec 6, 2012

I'm having the same issue also using OpenGL as my main content view. For me, everything works fine on Jelly Bean, but not in ICS (I get the black shadow overlay). The difference from the original post is that I'm not using a MapFragment, but SherlockFragment (my app does not contain maps).

@jfeinstein10
Copy link
Owner

Do you both have the most recent version of the code? I know that the guys in #62 didn't and then once they updated all was fine

@jfeinstein10
Copy link
Owner

Also try adding this code to force a redraw and tell me if it does anything

getSlidingMenu().setOnOpenedListener(new OnOpenedListener() {
  public void onOpened() {
    getSlidingMenu().invalidate();
  }
}

@jfeinstein10
Copy link
Owner

Oops, didn't mean to close it, sorry!

@aeroperf
Copy link

aeroperf commented Dec 6, 2012

I just tried your code snippit and it did not fix the problem. My library is 2 days old (Dec 4 date). I'll try to update it later today and try it again.

@nhaarman
Copy link

I'm having the same problem, I'm using the slidingright branch. I noticed this branch doesn't get updated as often as the master branch.

Is this issue resolved for the master branch and if so, will it be fixed as well for the slidingright branch?

@sbonaccorsi
Copy link

Hello,
I'm having the same problem, I'm using SlidingMenu left with Actionbarsherlock and Google maps Android API V2.
I'm using a SherlockFragment for the behind view and I get that. I tried the code above to solve the problem and didn't work. I get that.
device-2012-12-13-221318_2

@jfeinstein10
Copy link
Owner

Is there any way that you can stop map updates and drawing as soon as an open gesture starts?

@sbonaccorsi
Copy link

I tried to make a onStop on my class mapFragment and stop drawing marker on the map google and I get the same result. I tried to hide the fragment to see if I get the problem and i didn't get the problem, but isn't the good solution.
Sorry if my english isn't good ;)
Thanks

@nhaarman
Copy link

Any progress on this issue?

@redwarp
Copy link

redwarp commented Dec 19, 2012

I got a really ugly solution :

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

And, to call this function properly :

mapFragment = new SupportMapFragment() {
@OverRide
public android.view.View onCreateView(
android.view.LayoutInflater arg0,
android.view.ViewGroup arg1, Bundle arg2) {
View view = super.onCreateView(arg0, arg1, arg2);
setMapTransparent((ViewGroup) view);
return view;
};
};

Using the hierarchy viewer, I tried to identify what element in the view hierarchy was of the type SurfaceView, you then set the background to transparent... Hope this helps !

@jfeinstein10
Copy link
Owner

Hmm very strange. Do you have any idea why the background color might be visible outside the view itself?

@redwarp
Copy link

redwarp commented Dec 19, 2012

It happens that it's a problem with SurfaceViews in general : the way they work, as described : "the SurfaceView punches a hole in its window to allow its surface to be displayed" (http://developer.android.com/reference/android/view/SurfaceView.html) Somehow, it appears always on top, even when hidden, for some reason, and setting the background to transparent solves it somehow. Also, this black glitch only appears for ICS and under, it seems. On GS3, or Nexus 4 with jelly beans, it worked properly...

@fstefansen
Copy link

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

seems to solve it for me.

@redwarp
Copy link

redwarp commented Dec 19, 2012

Works for me as well. Nice one. A lot better than my ugly solution.

@aeroperf
Copy link

How would I implement this since I don't use a map fragment? I'm seeing the issue when using a SherlockFragment hosting OpenGL component.

@redwarp
Copy link

redwarp commented Dec 20, 2012

set the background of your GLSurfaceView to transparent will do the trick, and looks like setting zOrderOnTop works as well. The choice is yours :-)

@aeroperf
Copy link

Setting the background to transparent 'mGLView.setBackgroundDrawable(new ColorDrawable(0));' worked for me. Thanks!

@jfeinstein10
Copy link
Owner

Does somebody want to formally write this up for the README file?

@avatar21
Copy link
Author

avatar21 commented Jan 3, 2013

This works pretty well for me ...
It seems like it's the default background (which is black) of SurfaceView which is causing this bug ...

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

Thanks redwarp and others :), cheers.

@Spiderbezno
Copy link

I have the same problem, I use this option zOrderOnTop="true" to resolved the problem but with this the overlay objects in the map as button zoom, etc , are drawer rear thet map, you can't click but you can't see them.

@Malachiasz
Copy link

I used fixed with:

    GoogleMapOptions options = new GoogleMapOptions();
    options.zOrderOnTop(true);
    supportMapFragment = SupportMapFragment.newInstance(options);

but then I cannot use another fix for getting info when Map Fragment is added and supportMapFragment.getMap() returns map handler.

supportMapFragment = new SupportMapFragment() {
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            map = supportMapFragment.getMap();
            if (map != null) {
                initializeMap();
            }
        }
   };

my dirty workaround for that is now is simply using delay

    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
              map = supportMapFragment.getMap();
              if (map != null) {
                initializeMap();
              }
        }
    }, 200);

How are you dealing with that problem? initializeMap sets for example zoom level.

@durandt
Copy link

durandt commented Feb 18, 2013

Hi,

You're doing good job jfeinstein10, the bug is coming from GoogleApis, not from you!
The bug is documented on the map-apis bug tracker.
http://code.google.com/p/gmaps-api-issues/issues/detail?id=4639

But it says on the link above that we have to flood this link:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=4659
to get higher up in debug-prioritizing.

Coz', workarounds are nice, but don't make for nice maintainable code, please folk click the second link and "star" the issue :)

Regards,

Thibault D.

@ghost
Copy link

ghost commented Apr 2, 2013

The workaround that worked for me is to add a transparent view above the map in menu onOpen and then remove it in menu onClose

getSlidingMenu().setOnOpenListener(new OnOpenListener() {
public void onOpen() {
View dummyView = (View)findViewById(R.id.dummy_view);
dummyView.setVisibility(View.VISIBLE);
}
});

    getSlidingMenu().setOnCloseListener(new OnCloseListener() {
         public void onClose(){
             View dummyView = (View)findViewById(R.id.dummy_view);
             dummyView.setVisibility(View.GONE);
            }
    });

@KingWu
Copy link

KingWu commented Apr 12, 2013

Hi all,
I use redwarp's solution, i try to apple a style to control the window background color

<style name="AppBaseTheme" parent="Theme.Sherlock.Light.DarkActionBar"> #FFFFFFFF </style>

The both-side sliding menu's view is on top of the Google map view.
When closing the menu, all menu item is shown on top of google map.

Anyone know how to solve it?

@ankitclabs
Copy link

hi
is there any way to invalidat the map?

@nailgilaziev
Copy link

I have the same problem. I read this issue thread and I don't understand - is there any solution for the problem?
Please explain more clearly.

my problem on lg p970 (4.0.4) device.
on nexus 7 all works fine.
I extend SlidingFragmentActivity. And get map with next code:
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

Anyone can help me?

@ckakei
Copy link

ckakei commented Apr 26, 2013

I had the same problem with using Google Map v2 on the main activity.

I solved the problem by following carlonzo reply in #62
Putting a transparent view above the mapview layout.

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

    <FrameLayout
        android:id="@+id/map_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent" />

</RelativeLayout>

@jairosoares
Copy link

Solved. But the result is terrible!

@reixa00
Copy link

reixa00 commented Aug 29, 2013

@ckakei that worked for me. Previously I had another view too after the FrameLayout but they didn't work. After I put the transparent View that you said it worked like a charm.

Lots of thanks!

@durandt
Copy link

durandt commented Aug 29, 2013

Beware that Google as precisely released a fix for this issue and the tricky thing is that this patch will only apply to some compatible devices. You now have to do your tests at least on two different devices...
More info:
https://code.google.com/p/gmaps-api-issues/issues/detail?id=4659

@joecizac
Copy link

@jfeinstein10 thank you very much for such an awesome library.
Me too had this issue with black space showing for less than a second when you open the slidingMenu to a mapView; but i resolved it by updating the library and disabling HW acc ( @jfeinstein10 thanxxx again for the solution ) in SlidingMenu class ;-)

@Surabhi-Jain
Copy link

I am facing same problem on loading map v2 in same activity.
Scenario is,
I am displaying map in fragment inside view pager,with detail fragment,for map I have created fragment dynamically. I am using single activity so each screen is represented by a Fragment. NewsDetailsFragment includes a ViewPager (map).

When I navigate to the NewsDetailsFragment initially, the map is loaded, now if I load a new instance of the NewsDetailsFragment like on scrolling pager I am displaying my next record. The ViewPager in the 2nd NewsDetailsFragment wont display the map. In LogCat,Log shows that everything works fine, map is displaying and markers get set. But on place of map showing black screen.

If there is 1 loaded map ViewPager, any more NewsDetailsFragment wont show their maps, only if I press Back till I have no NewsDetailsFragment (hence no ViewPagers running), only then if I open a new instance of NewsDetailsFragment it will load the map.

@DarwinLouis
Copy link

The code snippet shared by @avatar21 works pretty well for me. :) Thanks man!

@NithyaPachiyappan
Copy link

The code is working well..thanks man..!! @avatar21

@hansnoordhof
Copy link

The snippet from @ckakei worked for me. Thanks !!!

@j3g
Copy link

j3g commented Mar 14, 2014

I've looked at both tickets closed and I don't see a comment from the Moderator about what his solution is...I see a " library-maps-support" but no documentation about when to use it. I looked at the one java file (SlidingMapActivity.java) and I don't see any special code. And to be clear i'm using a map fragment not a MapActivity.

Any info is appreciated.

@gtobar
Copy link

gtobar commented Apr 17, 2014

The snippet from @ckakei worked for me. Thanks !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests