java - 在 Android 中使用谷歌地图在自定义信息窗口上动画

标签 java android google-maps animation google-api

我正在尝试在我的 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), call showInfoWindow(). 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/

相关文章:

java - 在 Windows 7 中不从命令行强制终止 JVM

java - 在转换时覆盖对象

java - 从 Java(Web 应用程序)针对 Active Directory 2016 进行身份验证

android - 在 EditText 焦点上抑制软键盘的出现

android - GCM - Android 模拟器上的 PHONE_REGISTRATION_ERROR

google-maps - 谷歌地图信息窗口未正确显示

安卓 : open local map file

java - 正则表达式匹配除模式之外的所有内容

android - 我在哪里可以找到 Unity 中的构建系统选项?

android - Google Maps Android API : Failed to load map. 联系 Google 服务器时出错。这可能是 SSL Pinning 实现后的身份验证问题