Placing Zoom Controls in a MapView

jasonhudgins picture jasonhudgins · Nov 4, 2008 · Viewed 44.8k times · Source

I'm trying to get the zoom controls to show up in a mapview, the following code almost works, but the zoom controls appear in the top left of the mapview, not the bottom center like I'm specifying via setGravity(). Can someone enlighten me as to what I'm missing?

zoomView = (LinearLayout) mapView.getZoomControls();
zoomView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT)); 
zoomView.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
mapView.addView(zoomView);

These views/layouts are all constructed programmatically, there is no layout file to tweak.

Answer

jcrowson picture jcrowson · Mar 23, 2010

Add the following line to the OnCreate() method of your MapView Class:

view.setBuiltInZoomControls(true);