首页 > 解决方案 > 谷歌地图标记选项大小

问题描述

我正在尝试增加 google markerOptions 的大小,因为里面的文本并不完全可见......

这是我的代码,我没有找到设置大小的选项。

    MapsInitializer.initialize(getContext());
    mGoogleMap = googleMap;
    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    //Normalement on va devoir boucler sur toutes les coordonnées reçu pour créer tous les markers
    googleMap
            .addMarker(new MarkerOptions()
                    .position(new LatLng(50.200323, 4.897113))
                    .title("Collecte de Falmagne")
                    .snippet("Horaires de cette collecte : \n Lundi : 10H00-15H00 \n Mardi 13H00-17H00 \n Mercredi 8H00-12H00")
                    );

这是一张显示我的问题的图片

在此处输入图像描述

提前谢谢你,抱歉英语不好!

标签: javaandroiddictionarymarkercode-snippets

解决方案


另一种选择是创建一个布局并将其添加到自定义 InfoWindowAdapter。

custom_info_window.xml:

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:orientation="vertical">

    <TextView
        android:id="@+id/tv_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp"
        android:paddingStart="5dp"
        android:textColor="@color/blank"
        android:textSize="24sp"
        android:textStyle="bold" />    

    <TextView
        android:id="@+id/tv_subtitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/tv_title"
        android:background="@color/white"
        android:paddingLeft="5dp"
        android:paddingStart="5dp"
        android:singleLine="false"
        android:textColor="@color/black"
        android:textStyle="italic" />

 </RelativeLayout>

在 Activity/Fragment Map 中添加自定义适配器:

 private class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
     @Override
     public View getInfoWindow(Marker marker) {
        View view = getActivity().getLayoutInflater().inflate(R.layout.custom_info_window, null);
        TextView tvTitle = (TextView) view.findViewById(R.id.tv_title);
        TextView tvSubTitle = (TextView) view.findViewById(R.id.tv_subtitle);

        tvTitle.setText(marker.getTitle());
        tvSubTitle.setText(marker.getSnippet());
        return view;
     }

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }
 }

推荐阅读