Map padding
In general, Google Maps fills the entire container and its controls are displayed at the edges. They are as follows:
Zoom controls are displayed in the bottom right corner
My location button is displayed in the top right corner
Compass controls are displayed in the top left corner
Other than these, the Google Maps copyright information is displayed in the bottom-left corner.
There may be situations where you may have to display other information in place of these elements. To make this possible, you can pad the elements in the corners.
This can be done by calling the setPadding()
method on the GoogleMap
object. It takes pixels as an integer value to pad the left, top, right, and bottom edges.
It would be called as follows:
map.setPadding(400, 100, 100, 0);
This means that 400 pixels are padded in the left corner and 100 pixels are padded in the top and right corners.
Let's discuss this with an example. The code for the layout remains the same as we used in the beginning with MapFragment...