动画标记Google地图如何像Android中的图像所示? [英] How can animated marker google map like shown in image in android?

查看:54
本文介绍了动画标记Google地图如何像Android中的图像所示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Android的Google地图标记中添加这种类型的动画?

How can I add this type of animation in google map marker in android?

如果用户点击图标超过两秒钟,则可点击标记

If user tap icon for more than two second then marker clickable

如何在android中设置呢?

How can set this in android?

推荐答案

下面是循环方法的一个示例-首先是录制,然后是代码.

Here's an example of the circle approach - first the recording followed by the code.

这里的半径增长是线性的,但是显然在您的示例中是一个不同的函数(它随着扩展而变慢),因此您需要使用它.

The radius growth is linear here but is obviously a different function in your example (it slows down as it expands) so you'll need to work with that.

public void pulseCircleTest() {

    // arbitrary point
    LatLng pt = new LatLng(39.171755, -86.510632);

    // move map to point of interest
    CameraPosition cp = CameraPosition.builder().target(pt).zoom(8.0F).build();
    mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cp));

    // create a circle and start animation
    int color = Color.BLUE;
    float initialRadius = 10;
    float maxRadius = 20000f;
    CircleOptions co = new CircleOptions().center(pt).radius(initialRadius).strokeColor(color).fillColor(color).strokeWidth(1.0f);
    Circle c = mMap.addCircle(co);
    Circle c2 = mMap.addCircle(co);

    final Handler h = new Handler();
    h.postDelayed(new Fader(h,c, initialRadius, maxRadius, Color.BLUE, co), 300);
    h.postDelayed(new Fader(h,c2, initialRadius, maxRadius, Color.BLUE, co), 750);
}

private class Fader implements Runnable {
    private float radius, initialRadius, maxRadius;
    private int baseColor, color, initialColor;
    private Handler h;
    private Circle c;
    private float radiusJump = 400;
    int numIncrements, alphaIncrement;
    private CircleOptions co;

    public Fader(Handler h, Circle c, float initialRadius, float maxRadius, int initialColor, CircleOptions co) {
        this.initialRadius = initialRadius;
        this.initialColor = initialColor;
        this.maxRadius = maxRadius;
        this.h = h;
        this.c = c;
        this.co = co;
        reset();
    }

    private void reset() {
        radius = initialRadius;
        this.color = initialColor;
        this.baseColor = initialColor;
        numIncrements = (int)((maxRadius - initialRadius) / radiusJump);
        alphaIncrement = 0x100 / numIncrements;
        if (alphaIncrement <= 0) alphaIncrement = 1;
    }

    public void run() {
        int alpha = Color.alpha(color);
        radius = radius + radiusJump;
        c.setRadius(radius);
        alpha -= alphaIncrement;
        color = Color.argb(alpha, Color.red(baseColor), Color.green(baseColor), Color.blue(baseColor));
        c.setFillColor(color);
        c.setStrokeColor(color);

        if (radius < maxRadius) {
            h.postDelayed(this, 25);
        } else {
            c.remove();
            reset();
            c = mMap.addCircle(co);
            h.postDelayed(this, 2000);
        }

       //done
    }
}

这篇关于动画标记Google地图如何像Android中的图像所示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆