【问题标题】:How to customize appearence of android google maps api v2 info window?如何自定义 android google maps api v2 信息窗口的外观?
【发布时间】:2013-08-05 02:49:53
【问题描述】:

在我的 android 应用程序中,我有一个用于放置在地图上的标记的信息窗口。我想做这些事情:

  1. 使默认标记更大(现在太小了)
  2. 显示信息窗口时,其中的文本使宽度过长。有没有办法可以设置最大宽度?
  3. 如何增加标题和文本的字体大小?

谁能教我怎么做?

谢谢。

【问题讨论】:

标签: android google-maps-android-api-2 infowindow


【解决方案1】:

可能有点晚了,但您需要创建一个新的自定义适配器,您可以在这里查看:How to change Google Maps marker window Info

 mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

        @Override
        public View getInfoWindow(com.google.android.gms.maps.model.Marker arg0) {
            return null;
        }

        @Override
        public View getInfoContents(com.google.android.gms.maps.model.Marker marker) {
            LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService
                    (Context.LAYOUT_INFLATER_SERVICE);
            View mView = null;
            //using the id, you can store multiple types of markers on List's and change the layout
            if (marker.getId().equals(end.getId())) {
                mView = inflater.inflate(R.layout.custom_info_window, (ViewGroup) findViewById(R.id.map), false);
                ((TextView) mView.findViewById(R.id.txtTitle)).setText(marker.getTitle());
            }else{
                mView = inflater.inflate(R.layout.normal_info_window, (ViewGroup) findViewById(R.id.map), false);
                ((TextView) mView.findViewById(R.id.txtTitle)).setText(marker.getTitle());
                ((TextView) mView.findViewById(R.id.txtDescription)).setText(marker.getSnippet());
            }
            return mView;
        }
    });
    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {
                 //do whatever you need
        }
    });

在自定义视图中,您可以修改字体大小和其他内容,对于第一个点,可以在 MarkerOptions.setIcon 上修改标记图标,您可以在其中使用资产中的一个。

【讨论】:

    【解决方案2】:

    1:在地图上添加Marker时,可以在MarkerOptions中设置图标。制作自己的图标并使用它。

    2 & 3:在您的 GoogleMap 上设置onMarkerClickListener。在回调中,您可以创建并在地图上显示您自己的信息窗口视图(只需确保从 onMarkerClick() 回调中返回 false)

    【讨论】:

    • 如何创建自己的信息窗口?
    • 好吧,我想您会制作或扩充布局并以编程方式将其添加到屏幕上。 getMap() 返回的 MapView 扩展了 FrameLayout,因此您可以为您的信息窗口创建 FrameLayout.LayoutParams 并将其直接添加到 MapView。您可能不得不尝试移动地图并计算窗口的位置。
    猜你喜欢
    • 2014-11-13
    • 1970-01-01
    • 2013-08-05
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-09
    • 1970-01-01
    相关资源
    最近更新 更多