Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How to set bottom padding for Google Logo on Google Maps

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?

enter image description here

like image 841
rgoncalv Avatar asked Dec 13 '22 17:12

rgoncalv


1 Answers

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

like image 52
Droid Avatar answered Dec 17 '22 22:12

Droid