Google Maps Android API v2:借助ValueAnimator可视化搜索半径
作者:互联网
我想在Google地图视图中添加一个动画圆圈,类似于您在此图片上看到的圆圈.
圆圈应从中心脉动到最大半径,表示当前用户的位置和搜索区域.
这是相关的代码块
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);
}
});
使用此代码,我只能看到没有任何动画的静态圆形笔划.
任何帮助将不胜感激.
提前致谢.
解决方法:
简单:)
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();
标签:google-maps-api-2,android,google-maps,android-animation 来源: https://codeday.me/bug/20190930/1835718.html