我最近询问了有关将动画应用于标记弹出窗口(infowindow)的问题,并解释了为什么这是不可能的:
Note: The info window that is drawn is not a live view. The view is rendered as an image (using
View.draw(Canvas)
) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (e.g., after an image has loaded), callshowInfoWindow()
. Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.
经过更多研究,我发现了一个使用 V1 的项目,该项目可以在标记位置手动创建 View 。为此,另一个人做了这样的事情:
public void showPopup(View view, GeoPoint point, boolean centerPopup) {
removeAllViews();
MapView.LayoutParams lp = new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
point,
Utils.dipsToPixels(0.0f, mContext),
Utils.dipsToPixels(-12.0f, mContext),
MapView.LayoutParams.BOTTOM_CENTER);
if (centerPopup) {
getController().animateTo(point);
mIgnoreNextChangeEvent = true;
}
View balloon = mInflater.inflate(R.layout.balloon, null);
balloon.setLayoutParams(lp);
((ViewGroup) balloon.findViewById(R.id.balloonBody)).addView(view);
balloon.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.bounce_in));
addView(balloon);
}
因此他手动创建了一个气球 View 并将其附加到 MapView。
我一直在尝试使用 V2 来模拟同样的事情,但我无法做到,我什至不知道这是否可能。例如,我使用“GoogleMap”而不是“MapView”,我不确定这是否与 V1 和 V2 之间的一些差异有关。
我将添加目前为止所掌握的内容,仅供引用。我尝试从其他项目复制代码并尝试修改它,以便它可以在这个项目中工作,但我什至无法编译它。
public boolean onMarkerClick(Marker marker) {
map.removeAllViews();
MapView.LayoutParams lp = new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
marker.getPosition(),
Tools.dipsToPixels(0.0f, this),
Tools.dipsToPixels(-12.0f, this),
MapView.LayoutParams.BOTTOM_CENTER);
if (centerPopup) {
getController().animateTo(point);
mIgnoreNextChangeEvent = true;
}
View balloon = mInflater.inflate(R.layout.balloon, null);
balloon.setLayoutParams(lp);
((ViewGroup) balloon.findViewById(R.id.balloonBody)).addView(view);
balloon.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.bounce_in));
addView(balloon);
return false;
}
最佳答案
您无法将滚动 map 与其上方的任何 View 同步,即使您完成了这种解决方案,它也会显得滞后。
您是否尝试过此解决方法:https://stackoverflow.com/a/16147630/2183804 ?
关于java - Google map v2 中的动画信息窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16164278/