我正在尝试使用ValueAnimator
对MapboxMap上的折线进行动画处理。
我找到了很多解决方案,但是这些解决方案都在Google地图上,并且试图实现逻辑但没有运气,这是我到目前为止编写的代码:
public static void addHistoryLine(final MapboxMap mapboxMap, final List<LatLng> cords) {
final Polyline backGroundPolyline;
final Polyline foreGroundPolyline;
final ValueAnimator polylineAnimator;
final int size = cords.size();
final PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.width(3);
polylineOptions.color(Color.BLUE);
polylineOptions.addAll(cords);
backGroundPolyline = mapboxMap.addPolyline(polylineOptions);
final PolylineOptions foreGroundOptions = new PolylineOptions();
foreGroundOptions.width(3);
foreGroundOptions.color(Color.GREEN);
foreGroundPolyline = mapboxMap.addPolyline(foreGroundOptions);
polylineAnimator = ValueAnimator.ofInt(0, size);
polylineAnimator.setInterpolator(new LinearInterpolator());
polylineAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
try {
int val = (int) valueAnimator.getAnimatedValue();
Log.e("Animated Val: ", "value is: " + val);
List<LatLng> points = backGroundPolyline.getPoints();
int Pointsize = points.size();
int newPoints = (int) (size * (val / Pointsize));
List<LatLng> p = points.subList(val, newPoints);
foreGroundPolyline.setPoints(p);
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
polylineAnimator.setDuration(10000);
polylineAnimator.start();
polylineAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
Log.e("Animation", "Animation Start");
}
@Override
public void onAnimationEnd(Animator animation) {
Log.e("Animation", "Animation End");
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
}
我的想法是绘制背景多段线,然后通过计算其ValueAnimator. But I'm not able to do so. Any idea how can i calculate those new points to set into
foreGroundPolyline`的点和值来在其上重画一条新的多段线。