【问题标题】:Animate map Marker in GoogleMaps APIGoogle Maps API 中的动画地图标记
【发布时间】:2016-07-11 12:20:47
【问题描述】:

我正在尝试创建一个看起来像这样的自定义标记:

我的 XML 中的 drawable 看起来像这样:

<solid
    android:color="#0093e8"/>

<size
    android:width="120dp"
    android:height="120dp"/>

是否可以在标记上添加“波浪效果”,让波浪逐渐淡出(如图所示)?另外,这个动画应该一直在播放(不需要用户点击地图标记)我该怎么办?

【问题讨论】:

  • @SaravInfern 嘿,谢谢!
  • @SaravInfern 我认为那里的解决方案对我的情况没有帮助,因为它建议“动画”标记的位置。
  • 我认为解决您的问题的最佳方法是在标记上使用动画,因为通过使用动画,您可以在各种不同的情况下展示动态运动。检查此Github 和此SO question 以获取示例代码和信息以使标记反弹。

标签: android google-maps google-maps-markers


【解决方案1】:

我做了一些非常相似的事情,但我使用的是 GroundOverlay 而不是标记,首先我定义了我的自定义动画:

public class RadiusAnimation extends Animation {
    private GroundOverlay groundOverlay;

    public RadiusAnimation(GroundOverlay groundOverlay) {
        this.groundOverlay = groundOverlay;

    }
    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        groundOverlay.setDimensions( (100 * interpolatedTime) );
        groundOverlay.setTransparency( interpolatedTime );

    }


    @Override
    public void initialize(int width, int height, int parentWidth,int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
    }
}

然后我在 groundOverlay 上运行动画,在 onMapReady 之后:

...
  groundOverlay = mGoogleMap.addGroundOverlay(new GroundOverlayOptions()
                    .image(image)
                    .position(new LatLng(lat, lng), 100));
  groundAnimation = new RadiusAnimation(groundOverlay);
  groundAnimation.setRepeatCount(Animation.INFINITE);
  groundAnimation.setRepeatMode(Animation.RESTART);
  groundAnimation.setDuration(2000);
  mapView.startAnimation(groundAnimation); // MapView where i show my map
...

希望对你有帮助

【讨论】:

  • 感谢您的建议!会尝试是否可行:)
  • 我无法在我的 GoogleMap 对象上应用“startAnimation”方法。好像没有这样的
  • 它是在 MapView developers.google.com/android/reference/com/google/android/gms/… 而不是 GoogleMap 如果您使用 SupportMapFragment,您也可以使用 View mapView = mapFragment.getView();,它也应该可以工作
  • 嘿。谢谢,工作!我将尝试更改您的解决方案以完全符合我的设计要求并包含多个叠加层:)
  • @GeorgiKoemdzhiev 嗨,您介意分享一下您是如何使用多个叠加层做到这一点的吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-03
  • 2011-09-13
  • 2012-06-09
  • 1970-01-01
  • 2013-01-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多