我正在尝试在我的 Android 应用程序中使用自定义标记“气泡”。为此,我创建了一个返回并填充 View 的 InfoWindowAdapter。
但是,出于某种原因,它似乎不允许我将动画应用于该 View (或内部的任何内容)。我希望它以某种动画方式弹出,但我可能遗漏了一些东西。
这是我到目前为止尝试过的:
map.setInfoWindowAdapter(new InfoWindowAdapter() {
private final View contents = getLayoutInflater().inflate(R.layout.marker_layout, null);
public View getInfoWindow(Marker marker) {
TranslateAnimation animator = new TranslateAnimation(0.0f, 0.0f, 0.0f, 100.0f);
animator.setDuration(2000);
animator.setInterpolator(new AccelerateInterpolator());
animator.setFillAfter(true);
contents.findViewById(R.id.entity_name).clearAnimation();
contents.findViewById(R.id.entity_name).startAnimation(animator);
((TextView) contents.findViewById(R.id.entity_name)).setText(marker.getTitle());
return contents;
}
/* ... */
View 已成功创建并填充,但没有父动画。如果我将相同的动画应用于布局的另一个元素,它会完美地工作,所以我开始认为这可能与 Google map 使用信息窗口的方式有关?
最佳答案
出于一个简单的原因,您不能将动画应用到 InfoWindow
。您在 InfoWindow
中看到的不是您定义的布局,而是从中绘制的图像。这意味着您不能操纵此 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.
关于java - 在 Android 中使用谷歌地图在自定义信息窗口上动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16145221/