简体   繁体   English

Android-如何在Google地图上设置Google徽标的底部填充

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

In iOS, this is pretty easy. 在iOS中,这非常简单。

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. 不过,在Android中,我尝试通过android:paddingBottom=80dp"mapView.setPadding(0,0,0,80) xml来通过XML添加填充到地图底部。在两种情况下,地图会向上移动以及是否被剪切,并且会出现一个空格,实际上只有Google徽标应该向上移动,而地图应该保持全高。

Here's my xml: 这是我的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. 因此,mapView继续以全高继续运行,但是Google Maps的地图由于其填充而向上移动。 Is there a way to move up only the Google logo while the Google Maps' map stays intact? 有没有办法在Google地图的地图保持完整的情况下仅向上移动Google徽标?

在此处输入图片说明

MapView is just a FrameLayout container for the map. MapView只是地图的FrameLayout容器。 Instead, add the padding to the GoogleMap Object in your onMapReady callback. 相反,应在onMapReady回调中将填充添加到GoogleMap对象。 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 上面的值在我的情况下有效,与您的相似,但可能您需要进行一些测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM