GoogleMap显示Custom Infowindow两次 - 一次Inside Other

时间:2015-07-30 18:35:22

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

我正在使用标记和InfoWindow加载GoogleMap。但是我的信息窗口会出现两次(一个默认值,一个用作我的xml背景的图像。enter image description here)作为附加图像。我必须使用我的自定义9补丁背景。我正在添加我用于此的代码。请检查并租赁指导我做错了什么。

我的CustomInfoWindow类。

 public class CustomInfoWindow implements GoogleMap.InfoWindowAdapter {
    Context mContext;
    LayoutInflater mInflater;
    TextView mTxtTitle;
    TextView mTxtAddress;
    TextView mTxtNavigation;

    public CustomInfoWindow(Context context) {
        this.mContext = context;
        this.mInflater=LayoutInflater.from(mContext);
    }

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

    @Override
    public View getInfoContents(Marker marker) {
        // Getting view from the layout file info_window_layout
        View rootView = mInflater.inflate(R.layout.custom_info_window, null);
        mTxtTitle= (TextView)rootView.findViewById(R.id.txt_window_title);
        mTxtAddress= (TextView)rootView.findViewById(R.id.txt_window_address);
        mTxtNavigation= (TextView)rootView.findViewById(R.id.txt_window_nav_icon);

        return rootView;
    }
}

我正在膨胀的xml文件:

<?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:background="@drawable/info_window"
    android:orientation="horizontal">


    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin30"
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <com.ishippo.shipper.customviews.TextViewBold
            android:id="@+id/txt_window_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/pickup_loc_title"
            android:textColor="@color/black" />

        <com.ishippo.shipper.customviews.TextViewBold
            android:id="@+id/txt_window_address"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/margin5"
            android:text="@string/pickup_loc_title"
            android:textColor="@color/black" />
    </LinearLayout>


    <View
        android:layout_width="@dimen/height1"
        android:layout_height="match_parent"
        android:layout_marginBottom="@dimen/margin20"
        android:layout_marginTop="@dimen/margin20"
        android:layout_toRightOf="@+id/txt_window_address"
        android:background="@color/hint_color" />


    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin20"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <com.ishippo.shipper.customviews.TextViewBold
            android:id="@+id/txt_window_nav_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableTop="@mipmap/navigate"
            android:text="@string/navigate"
            android:textColor="@color/black" />
    </LinearLayout>


</LinearLayout>

我打电话通过以下代码添加窗口:

mGmap.setInfoWindowAdapter(new CustomInfoWindow(getActivity()));

1 个答案:

答案 0 :(得分:0)

我知道它有点老问题,但你所要做的就是替换你的getInfoWindow()和getInfoContents()方法。

@Override
public View getInfoWindow(Marker marker) {
    // Getting view from the layout file info_window_layout
    View rootView = mInflater.inflate(R.layout.custom_info_window, null);
    mTxtTitle= (TextView)rootView.findViewById(R.id.txt_window_title);
    mTxtAddress= (TextView)rootView.findViewById(R.id.txt_window_address);
    mTxtNavigation= (TextView)rootView.findViewById(R.id.txt_window_nav_icon);

    return rootView;
}

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