How can i customize the position of the builtin zoom controls in a GoogleMap V2 ?
There are a lot of questions related to this topic for the Version 1 of Google Maps library.
Placing Zoom Controls in a MapView
How to reposition built-in zoom controls in MapView?
How to layout zoom Control with setBuiltInZoomControls(true)?
However, i wasn't able to find any questions in relation to the V2 of the library.
In the V2, there's no method
(LinearLayout) mapView.getZoomControls();
all the previously mentioned questions becomes obsolete.
Thanks in advance
Google Maps - The Default Controls When showing a standard Google map, it comes with the default control set: Zoom - displays a slider or "+/-" buttons to control the zoom level of the map.
Users can zoom the map by clicking the zoom controls. They can also zoom and pan by using two-finger movements on the map for touchscreen devices.
Important Methods of Zoom ControlsZoomControl zoomControls = (ZoomControls) findViewById(R. id. simpleZoomControl); show(): This method is used to show the zoom controls on the App UI.
The Maps API provides built-in zoom controls that appear in the bottom right hand corner of the map. These are disabled by default, but can be enabled by calling UiSettings. setZoomControlsEnabled(true) .
Depending on what you're trying to do, you might find GoogleMap.setPadding() useful (added in September 2013).
map.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
From the API docs:
This method allows you to define a visible region on the map, to signal to the map that portions of the map around the edges may be obscured, by setting padding on each of the four edges of the map. Map functions will be adapted to the padding. For example, the zoom controls, compass, copyright notices and Google logo will be moved to fit inside the defined region, camera movements will be relative to the center of the visible region, etc.
Also see the description of how padding works in GoogleMap.
Yes, you can change position of ZoomControl and MyLocation button with small hack. In my sample I have SupportMapFragment, which is inflated from xml layout.
View ids for ZoomControl and MyLocation button:
ZoomControl id = 0x1 MyLocation button id = 0x2
Code to update ZoomControl position:
// Find map fragment SupportMapFragment mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.map); // Find ZoomControl view View zoomControls = mapFragment.getView().findViewById(0x1); if (zoomControls != null && zoomControls.getLayoutParams() instanceof RelativeLayout.LayoutParams) { // ZoomControl is inside of RelativeLayout RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) zoomControls.getLayoutParams(); // Align it to - parent top|left params.addRule(RelativeLayout.ALIGN_PARENT_TOP); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); // Update margins, set to 10dp final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics()); params.setMargins(margin, margin, margin, margin); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With