地图覆盖物上的弹出气泡在点击后会随机消失

4
我有一个应用程序,使用mapview-overlay-manager代码在MapView上绘制地图标记,并使用来自Web API的LazyLoadManager。当我拖动地图时,标记会按预期加载/取消加载。
当我点击标记时,我会填充一个balloon.xml文件,并使用它在标记上方显示气球。这就是问题所在。它能够正常工作,但突然间(我无法重复)气球覆盖层将停止在屏幕上显示。
虽然很奇怪,但标记仍然显示已被点击,但气球却不再显示。我已经检查过气球不为空(它确实不为空),并且itemInfo也不为空。调用.addview(...)后,它只是没有被添加到MapView中,但所有参数都是有效的。
另外:每当发生这种情况时,所有叠加层都会变得非常暗淡,叠加层阴影从半透明变成黑色。我不知道是什么原因导致的,但它同时发生,这使我相信它是一个绘制问题。
以下是上述问题的代码。如有任何提示/想法等,将不胜感激。
@Override
        public boolean onSingleTap(MotionEvent e, ManagedOverlay overlay, GeoPoint point, ManagedOverlayItem item) {

            if(mBalloon != null) 
            {
                mMapView.removeView(mBalloon);
                mBalloon = null; 
            } 

            if(item != null) {
                //Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
                MapView.LayoutParams balloonLayoutParams = new MapView.LayoutParams(350, MapView.LayoutParams.WRAP_CONTENT, item.getItemInfo().getMarkerPoint(mMapView.getProjection()), MapView.LayoutParams.BOTTOM_CENTER);


                if(mBalloon == null) {
                    if(mLayoutInflater == null) {
                        mLayoutInflater = getLayoutInflater();
                    }
                    ViewGroup parent = (ViewGroup)mMapView.getParent(); 
                    mBalloon = (BalloonLayout) mLayoutInflater.inflate(R.layout.balloon_layout, parent, false); 


                } 

                TextView title = (TextView)mBalloon.findViewById(R.id.title); 
                title.setText(item.getItemInfo().getTitle()); 

                TextView subTitle = (TextView)mBalloon.findViewById(R.id.subTitle); 
                subTitle.setText(item.getItemInfo().getBalloonSubTitle()); 

                if(DEBUG) Log.d(TAG, "Setting on click listener.");
                ((ImageButton)mBalloon.findViewById(R.id.go_button)).setOnClickListener(new ViewItemInfoListener(item.getItemInfo()));

                mMapView.addView(mBalloon, balloonLayoutParams);
            }
            return false;

        }
    });

    // Fires off the background event to get the 
    overlayManager.populate();
}
2个回答

0
你有没有考虑在 OnDrag 期间:移除所有标记并保存到临时列表中,启动一个计时器(大约200-500毫秒),然后在计时器到期后重新填充标记。如果在计时器到期之前发生另一个 OnDrag,则重新启动计时器。

0

好的,我找到了问题所在。有一个父方法调用了这个方法。不幸的是,这个方法被调用了两次。一次在onFocusChanged()中,一次在onCreate()中。移除其中一个就解决了问题。图标和气球因此重复绘制。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接