【问题标题】:unwanted white frame surrounds my customized GoogleMaps Info Window不需要的白框围绕着我自定义的 GoogleMaps 信息窗口
【发布时间】:2017-04-14 01:47:09
【问题描述】:

我使用自定义的信息窗口,以便获得灰色背景和白色文本颜色。然而,我在它周围有一个白框。我希望所有信息窗口都是灰色的,包括指向该点的三角形边缘。

我在我的Activity 中使用此代码:

map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
    @Override  // Use default InfoWindow frame
    public View getInfoWindow(Marker marker) { return null; }
    @Override // Defines the contents of the InfoWindow
    public View getInfoContents(Marker marker) {
        View v = getLayoutInflater().inflate(R.layout.map_info_window, null);
        TextView tv_location = (TextView) v.findViewById(R.id.tv_location);
        tv_location.setText(marker.getTitle());
        return v;
    }});

这是我的布局:

<!--?xml version="1.0" encoding="utf-8"?-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map_info_window"
    android:layout_width="match_parent"
    android:background="@color/light_grey"
    android:orientation="horizontal"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/tv_location"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/white" />

</LinearLayout>

【问题讨论】:

标签: android android-layout google-maps-api-3


【解决方案1】:

您必须覆盖 getInfoWindow () 方法并在该函数中扩展您的自定义布局。

来自Documentation

public abstract View getInfoWindow (Marker marker)

为标记提供自定义信息窗口。如果此方法返回一个 视图,它用于整个信息窗口。如果您更改此视图 调用此方法后,这些更改不一定是 反映在渲染的信息窗口中。如果此方法返回 null , 将使用默认的信息窗口框架,内容由 getInfoContents(Marker).

 @Override  // Use default InfoWindow frame
    public View getInfoWindow (Marker marker){
        View v = getLayoutInflater().inflate(R.layout.map_info_window, null);
        TextView tv_location = (TextView) v.findViewById(R.id.tv_location);
        tv_location.setText(marker.getTitle());
        return v;
    }
    @Override // Defines the contents of the InfoWindow
    public View getInfoContents (Marker marker){
        // TODO Auto-generated method stub
        return null;
    }

所以我认为你应该反转你的函数实现。

【讨论】:

    猜你喜欢
    • 2017-12-14
    • 2013-01-15
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-24
    • 2021-12-15
    相关资源
    最近更新 更多