gpt4 book ai didi

android - 在 Android 上添加到 map 时如何为标记设置动画?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:24:46 26 4
gpt4 key购买 nike

我想在将 map 标记添加到 map 时对其进行动画处理。

用户应该看到 map 上有他周围的标记。每个新标记都应该反弹。

最佳答案

您可以实现 onMarkerClick() 并使标记在用户点击它时反弹。试试下面的代码实现。我试过了,效果很好。

 private Marker mPerth;  
private Marker mPerth = mMap.addMarker(new MarkerOptions()
.position(PERTH)
.title("Perth")
.snippet("Population: 1,738,800"));
  @Override   
public boolean onMarkerClick(final Marker marker)
{
// This causes the marker at Perth to bounce into position when it is clicked.
if (marker.equals(mPerth)) {
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
Projection proj = mMap.getProjection();
Point startPoint = proj.toScreenLocation(PERTH);
startPoint.offset(0, -100);
final LatLng startLatLng = proj.fromScreenLocation(startPoint);
final long duration = 1500;
final Interpolator interpolator = new BounceInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
float t = interpolator.getInterpolation((float) elapsed / duration);
double lng = t * PERTH.longitude + (1 - t) * startLatLng.longitude;
double lat = t * PERTH.latitude + (1 - t) * startLatLng.latitude;
marker.setPosition(new LatLng(lat, lng));
if (t < 1.0) {
// Post again 16ms later.
handler.postDelayed(this, 16);
}
}
});
}
// We return false to indicate that we have not consumed the event and that we wish
// for the default behavior to occur (which is for the camera to move such that the
// marker is centered and for the marker's info window to open, if it has one).
return false;
}

除了 onClick 事件之外,您还可以在您的应用程序中添加标记时使用它。我希望这只是你想要的。

关于android - 在 Android 上添加到 map 时如何为标记设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8191582/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com