java - Google map v2 中的动画信息窗口

标签 java android animation google-maps-android-api-2

我最近询问了有关将动画应用于标记弹出窗口(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.

经过更多研究,我发现了一个使用 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/

相关文章:

java - Tapestry 5 - 将页面类名称与 URL 分离

java - 表单应用程序编码值在 Spring 休息中不起作用

android - 在 Android Wear 中使用现有数据库

java - 如何在JavaFX中将复选框绑定(bind)到变量?

javax.crypto.BadPaddingException : pad block corrupted

android - Fleetboard 上的 TLS 1.2

android - soong/android.bp 构建是如何工作的?

angular 2 动画在 *ng 中仅用于一个元素

javascript - 数组替换后的 VueJS 动画

.net - .NET 中的动画