gpt4 book ai didi

android - 在 MapView 上点击 OverlayItem 后弹出气球随机消失

转载 作者:太空宇宙 更新时间:2023-11-03 11:23:26 24 4
gpt4 key购买 nike

我有一个使用 mapview-overlay-manager 的应用程序使用 Web API 中的 LazyLoadManager 在 MapView 上绘制 map 标记的代码。当我拖动 map 时,标记会按预期加载/卸载。

在点击标记时,我会膨胀一个 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();
}

最佳答案

您是否考虑过在 OnDrag 期间:删除所有标记并保存在临时列表中,启动计时器(可能 200-500 毫秒),然后在计时器到期后重新填充标记。如果在计时器到期之前发生另一个 OnDrag,则重新启动计时器。

关于android - 在 MapView 上点击 OverlayItem 后弹出气球随机消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3238898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com