我需要显示一个Google地图标记的Infowindow,底部没有小三角形。请检查我附上的图像。
我尝试通过更改setInfoWindowAnchor来设置,但它不起作用。任何人都可以帮我吗?
marker_info.setInfoWindowAnchor(0,0)
答案 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;
}
}
结果:
示例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;
}
}
结果:
注意,这是使用的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>