rgo*_*alv 2 java android google-maps google-maps-api-3
在iOS中,这非常简单。
不过,在Android中,我尝试通过xml和in android:paddingBottom=80dp"以及通过编程将填充添加到地图底部mapView.setPadding(0,0,0,80)。在这两种情况下,地图都将向上移动以及是否被剪切,并且会出现一个空格,实际上只有Google徽标应该向上移动,而地图应该保持全高。
这是我的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" />
Run Code Online (Sandbox Code Playgroud)
因此,mapView继续以全高继续运行,但是Google Maps的地图由于其填充而向上移动。有没有办法在Google地图的地图保持完整的情况下仅向上移动Google徽标?
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);
}
Run Code Online (Sandbox Code Playgroud)
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));
}
Run Code Online (Sandbox Code Playgroud)
The values above worked in my case, that is similar to yours but probably you need to do some tests
| 归档时间: |
|
| 查看次数: |
1188 次 |
| 最近记录: |