自定义InfoWindowAdapter没有背景

时间:2013-12-21 21:02:28

标签: android google-maps

我有一个奇怪的问题 我设计了一个应用程序,用户可以在Google map ver 2上查看某些内容

我已经像这样使用了InfoWindowAdapter:

public class PopupAdapter implements  InfoWindowAdapter {
LayoutInflater inflater=null;
View view;
public PopupAdapter(LayoutInflater inflater) {
this.inflater=inflater;
view = this.inflater.inflate(R.layout.custom_info_window,null);
}

@Override
public View getInfoContents(Marker marker) {
// TODO Auto-generated method stub
return null;
}

@Override
public View getInfoWindow(Marker marker) {
final String title = marker.getTitle();
final TextView titleUi = ((TextView) view.findViewById(R.id.title));
if (title != null) {
titleUi.setText(title);
} 
else {
titleUi.setText("");
}
final String snippet = marker.getSnippet();
final TextView snippetUi = ((TextView) view.findViewById(R.id.snippet));
if (snippet != null) {
    snippetUi.setText(snippet);
}else {
     snippetUi.setText("");
} 
 return view;
}

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_launcher"/>
    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="12dp"
        android:textStyle="bold"/>
    <TextView
        android:id="@+id/snippet"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="10dp"/>
    </LinearLayout>

 </LinearLayout>

但是当我在我的标记上弹出时,它没有任何背景,它在地图上只显示一个没有弹出框的简单文本

我试图解决这个问题,但似乎有点不寻常 谁能帮帮我吗 ??? 非常感谢你

1 个答案:

答案 0 :(得分:2)

  

但是当我在我的标记上弹出时,它没有任何背景,它在地图上只显示一个没有弹出框的简单文本

这就是你要求它做的事情,重写getInfoWindow()。如果您需要标准信息窗口框架,请改为覆盖getInfoContents()。或者,将您自己的框架作为View的{​​{1}}的一部分包含在内。