无法获得Android系统中googlemap V2上标记的自定义信息窗口的点击事件。

问题描述 投票:0回答:3

我通过以下方式在标记上显示自定义的infoWindow。参考.现在我可以显示自定义信息窗口,如enter image description here

但问题是,我无法在每个按钮上获得右键事件,例如,当我点击button1时,它调用button2的touchlistener等等。

this.button1Listener = new OnInfoWindowElemTouchListener(
            button1, getResources().getDrawable(
                    R.drawable.ic_plusone_medium_off_client),
            getResources().getDrawable(
                    R.drawable.ic_plusone_tall_off_client)) {
        @Override
        protected void onClickConfirmed(View v, Marker marker) {
            // Here we can perform some action triggered after clicking the
            // button

            Toast.makeText(MapActivity.this, "Button1", Toast.LENGTH_SHORT)
                    .show();

        }
    };

this.button2Listener = new OnInfoWindowElemTouchListener(
                button2, getResources().getDrawable(
                        R.drawable.ic_plusone_medium_off_client),
                getResources().getDrawable(
                        R.drawable.ic_plusone_tall_off_client)) {
            @Override
            protected void onClickConfirmed(View v, Marker marker) {
                // Here we can perform some action triggered after clicking the
                // button

            Toast.makeText(MapActivity.this, "Button2", Toast.LENGTH_SHORT)
                    .show();

        }
    };

this.button3Listener = new OnInfoWindowElemTouchListener(
                button3, getResources().getDrawable(
                        R.drawable.ic_plusone_medium_off_client),
                getResources().getDrawable(
                        R.drawable.ic_plusone_tall_off_client)) {
            @Override
            protected void onClickConfirmed(View v, Marker marker) {
                // Here we can perform some action triggered after clicking the
                // button

            Toast.makeText(MapActivity.this, "Button3", Toast.LENGTH_SHORT)
                    .show();

        }
    }; and so on.......




this.button1.setOnTouchListener(button1Listener);
        this.button2.setOnTouchListener(button2Listener);
        this.button3.setOnTouchListener(button3Listener);
        .......
        // googleMap.setInfoWindowAdapter(null);
        googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

        // Use default InfoWindow frame
        @Override
        public View getInfoWindow(Marker marker) {

            return null;
        }

        // Defines the contents of the InfoWindow
        @Override
        public View getInfoContents(Marker marker) {

            button1Listener.setMarker(marker);
            button2Listener.setMarker(marker);
            button3Listener.setMarker(marker);
            ......

            // We must call this to set the current marker and infoWindow
            // references
            // to the MapWrapperLayout
            mapWrapperLayout.setMarkerWithInfoWindow(marker, infoWindow);
            return infoWindow;

        }

    });

请告诉我,我做错了什么?有时代码工作得很完美,但大多数时候它不工作。

android google-maps google-maps-markers infowindow
3个回答
0
投票

谷歌地图V2中的InfoWindow是一个信息窗口。形象,库将它们全部渲染成图像。请阅读 "自定义信息窗口 "中的 "注意"。地图Android API v2.

所以,所有的按钮,你添加到将无法工作。

如果你真的想这样做,你必须做一些代码。我找到了一个 此处


0
投票

终于,我解决了这个按钮点击事件不匹配的问题,问题就在这里。

// MapWrapperLayout initialization
    // 39 - default marker height
    // 20 - offset between the default InfoWindow bottom edge and it's content bottom edge 
    mapWrapperLayout.init(map, getPixelsFromDp(this, 39 + 20)); 

所以我就把

 mapWrapperLayout.init(map, getPixelsFromDp(this, 39 + 20)); 

改成了

mapWrapperLayout.init(map, getPixelsFromDp(this, 0)); 

所以,信息窗底边和内容之间不会有任何偏移。

希望能帮到大家。

© www.soinside.com 2019 - 2024. All rights reserved.