Google Maps Android API v2: Visualizing the search radius with the helping of ValueAnimator

自作多情 提交于 2019-12-29 04:06:09

问题


I want to add an animated circle to Google Maps view similar to the circle you see on this image.

The circle should be pulsing from the center to the largest radius indicating current user's location and the area of searching.

Here is relevant code block

Circle circle = mMap.addCircle(new CircleOptions()
     .center(new LatLng(lat, lon))
     .strokeColor(Color.CYAN).radius(1000));
    valueAnimator = new ValueAnimator();
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
        float animatedFraction = valueAnimator.getAnimatedFraction();
         circle.setRadius(animatedFraction * 1000);
         circle.setStrokeWidth(1 + animatedFraction * 7);
         }
        });

With this code I am only able to see static circle stroke without any animation.

Any help will be appreciated. Thanks in advance.


回答1:


Simply :)

    final Circle circle = MAP.addCircle(new CircleOptions().center(EGYPT)
            .strokeColor(Color.CYAN).radius(100));

    ValueAnimator vAnimator = new ValueAnimator();
    vAnimator.setRepeatCount(ValueAnimator.INFINITE);
    vAnimator.setRepeatMode(ValueAnimator.RESTART);  /* PULSE */
    vAnimator.setIntValues(0, 100);
    vAnimator.setDuration(1000);
    vAnimator.setEvaluator(new IntEvaluator());
    vAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    vAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float animatedFraction = valueAnimator.getAnimatedFraction();
            // Log.e("", "" + animatedFraction);
            circle.setRadius(animatedFraction * 100);
        }
    });
    vAnimator.start();


来源:https://stackoverflow.com/questions/17278015/google-maps-android-api-v2-visualizing-the-search-radius-with-the-helping-of-va

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!