地图标记信息窗口底部没有小三角形

时间:2015-06-24 05:11:16

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

我需要显示一个Google地图标记的Infowindow,底部没有小三角形。请检查我附上的图像。

enter image description here

我尝试通过更改setInfoWindowAnchor来设置,但它不起作用。任何人都可以帮我吗?

marker_info.setInfoWindowAnchor(0,0)

1 个答案:

答案 0 :(得分:8)

要使用speechbubble,请使用getInfoContents()覆盖。

为了不使用speechbubble,请使用getInfoWindow()覆盖。

示例1:

public class MyCustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {

    private final View myContentsView;

    MyCustomInfoWindowAdapter() {
        myContentsView = getLayoutInflater().inflate(
                R.layout.info_window, null);
    }

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

    @Override
    public View getInfoContents(Marker marker) {

        TextView tvTitle = ((TextView) myContentsView
                .findViewById(R.id.txtTitle));
        TextView tvSnippet = ((TextView) myContentsView
                .findViewById(R.id.txtSnippet));

        tvTitle.setText(marker.getTitle());
        tvSnippet.setText(marker.getSnippet());

        return myContentsView;
    }
}

结果:

using speechbubble

示例2:

public class MyCustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {

    private final View myContentsView;

    MyCustomInfoWindowAdapter() {
        myContentsView = getLayoutInflater().inflate(
                R.layout.info_window, null);
    }

    @Override
    public View getInfoWindow(Marker marker) {
        TextView tvTitle = ((TextView) myContentsView
                .findViewById(R.id.txtTitle));
        TextView tvSnippet = ((TextView) myContentsView
                .findViewById(R.id.txtSnippet));

        tvTitle.setText(marker.getTitle());
        tvSnippet.setText(marker.getSnippet());

        return myContentsView;
    }

    @Override
    public View getInfoContents(Marker marker) {

       return null;
    }
}

结果:

No Speechbubble

注意,这是使用的info_window.xml布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="20dp"
    android:orientation="vertical"
    android:background="#000000">

    <TextView
        android:id="@+id/txtTitle"
        android:textColor="#D3649F"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/txtSnippet"
        android:textColor="#D3649F"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>