简体   繁体   English

android mapbox:我如何为标记设置动画,例如标记从屏幕顶部掉落?

[英]android mapbox: how can i animate markers, like marker falling from the top of screen?

My goal is to create a marker on a map with falling animation from the top of screen. 我的目标是在地图上创建一个标记,并从屏幕顶部开始放下动画。 I don't know how to solve it. 我不知道该怎么解决。 How could I achieve that? 我该如何实现?

Add this method: 添加此方法:

private void dropPinEffect(final Marker marker) {
    // Handler allows us to repeat a code block after a specified delay
    final android.os.Handler handler = new android.os.Handler();
    final long start = SystemClock.uptimeMillis();
    final long duration = 1500;

    // Use the bounce interpolator
    final android.view.animation.Interpolator interpolator =
            new BounceInterpolator();

    // Animate marker with a bounce updating its position every 15ms
    handler.post(new Runnable() {
        @Override
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            // Calculate t for bounce based on elapsed time
            float t = Math.max(
                    1 - interpolator.getInterpolation((float) elapsed
                            / duration), 0);
            // Set the anchor
            marker.setAnchor(0.5f, 1.0f + 14 * t);

            if (t > 0.0) {
                // Post this event again 15ms from now.
                handler.postDelayed(this, 15);
            } else { // done elapsing, show window
                marker.showInfoWindow();
            }
        }
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM