将标记关闭屏幕或开始位置,然后开始动画。
注意.setAnchor此方法中使用被添加到谷歌地图API第2版2013年5月
我刚才得到这个工作了一个标记通过调整额外样品地图演示,我不不喜欢这个实现的性能。最重要的部分是将标记从屏幕上关闭或关闭在起始位置。我正在使用上面的屏幕。
锚标记戏外.setAnchor(.5f,(屏幕上方标记标记/尺寸)的大小)//对地图演示珀斯为约1207米为我的测试电话。将动画更改为弹回相同的值对于我的测试电话,它的值为6f。
private void addMarkersToMap() {
// A few more markers for good measure.
mPerth = mMap.addMarker(new MarkerOptions().position(PERTH)
.title("Perth").snippet("Population: 1,738,800")
.anchor(.5f, 6f)
);
改变动画所以它反弹至(以上标记物的标记物/尺寸屏幕的大小)(我的测试电话上6F)。我只是使用onclick处理程序,因为它已经设置为反弹并调整为6f并且持续时间更长。因此,在所有标记添加到地图后,我点击了点击处理程序。
this.onMarkerClick(mPerth);
更改的onMarkerClick处理程序与6f和更长的持续时间。
@Override
public boolean onMarkerClick(final Marker marker) {
if (marker.equals(mPerth)) {
// This causes the marker at Perth to bounce into position when it
// is clicked.
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
final long duration = 2500;
final Interpolator interpolator = new BounceInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
float t = Math.max(
1 - interpolator.getInterpolation((float) elapsed
/duration), 0);
marker.setAnchor(0.5f, 1.0f + 6 * t);
if (t > 0.0) {
// Post again 16ms later.
handler.postDelayed(this, 16);
}
}
});
} else if (marker.equals(mAdelaide)) {
// This causes the marker at Adelaide to change color.
marker.setIcon(BitmapDescriptorFactory.defaultMarker(new Random()
.nextFloat() * 360));
}
// 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;
}
好运