2

I was viewing a different question Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps) and as you can see he's using the requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); to make the map v2 use the full screen. I tried this but the my location button is partially covered by the action bar on mine unlike his. Does anyone know how to move it down slightly?

Thanks!

Mine looks like this

Community
  • 1
  • 1
tkblackbelt
  • 391
  • 2
  • 10

2 Answers2

3

Unfortunately you don't have any control over this button. Obviously, you can search for this button id in android sources and change layout params manually from the code, but I definitely wouldn't do that.

This button is super easy to implement yourself. So I recommend to disable built-in "locate me" button and implement your own which will be positioned right below the action bar.

To disable it use:

googleMap.setMyLocationEnabled(false);

New button onClick method content:

googleMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(googleMap.getMyLocation().getLatitude(),
                                                                 googleMap.getMyLocation().getLongitude())));
Pavel Dudka
  • 20,754
  • 7
  • 70
  • 83
  • Thanks! I actually had to do the following below. I was getting a location layer not enabled exception otherwise. map.setMyLocationEnabled(true); uiSettings.setMyLocationButtonEnabled(false); – tkblackbelt Feb 22 '13 at 19:03
1

You can just get the view by its id and re-set the top margin Apparently the id is always 2, but this isn't documented and your app will break when/if the id ever changes. Like Pavel said, it's safer to make your own location button and wire it up.

Unfortunately, calling ActionBar.getHeight() in your onCreate will always return 0 since layout hasn't finished. The way to get the real heigh is by using a listener on the ViewTreeObserver:

mainLayout.getViewTreeObserver().addOnGlobalLayoutListener(
     new ViewTreeObserver.OnGlobalLayoutListener() {
          public void onGlobalLayout() {
               int actionBarHeight = getActionBar().getHeight();
               // TODO: set margin of views dependent on actionbar height
               // remove the listener
               mainLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
          }
     }
}
Krylez
  • 17,414
  • 4
  • 32
  • 41