In iOS, this is pretty easy.
In Android though, I've tried adding padding to the bottom of the map both through xml as in android:paddingBottom=80dp"
as well as programmatically as in mapView.setPadding(0,0,0,80)
. In both cases, the map moves up as well as if it got cut and a blank space appears where actually only the Google logo should have moved up while the map should have remained with full height.
Here's my xml:
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
So, the mapView continues with full height but the Google Maps' map moves up because of the padding. Is there a way to move up only the Google logo while the Google Maps' map stays intact?
MapView is just a FrameLayout container for the map. Instead, add the padding to the GoogleMap Object in your onMapReady callback. Like so:
@Override
public void onMapReady(GoogleMap map) {
map.setPadding(0,0,0,80);
}
Also remember the values for paddings here are in pixels, you can use this function to do the conversion:
public static int dpToPx(int dp, Context context) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
}
public static void setPaddingForGoogleLogo(GoogleMap map, Context context) {
map.setPadding(LayoutUtils.dpToPx(15, context),
LayoutUtils.dpToPx(45, context),
LayoutUtils.dpToPx(0, context),
LayoutUtils.dpToPx(85, context));
}
The values above worked in my case, that is similar to yours but probably you need to do some tests
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