实际上,我现在就试着做它已经准备好了。这是我第一次做动画的方式。
bundle id
我在其中画了一条路径,但我无法同时添加动画并使其连续播放和重复。我实际上想制作一个应用程序,在 android 上使用画布在谷歌地图上显示风向。{{3} }在java和android中这样做的方法是什么,我应该如何进行?
public class CustomMapView extends MapView implements OnMapReadyCallback {
private Wind windList;
int framesPerSecond = 60;
long animationDuration = 15000; // 5 seconds toplam animasyon hareket süresi..
long startTime;
private long elapsedTime;
private OnMapReadyCallback onMapReadyCallback;
private GoogleMap googleMap;
private int aci;
private Paint paint;
public CustomMapView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
this.startTime = System.currentTimeMillis();
this.postInvalidate();
}
public Wind getWindList() {
return windList;
}
public void setWindList(Wind windList) {
this.windList = windList;
}
@Override
public void getMapAsync(OnMapReadyCallback onMapReadyCallback) {
this.onMapReadyCallback = onMapReadyCallback;
super.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
this.googleMap = googleMap;
if (onMapReadyCallback != null) {
onMapReadyCallback.onMapReady(googleMap);
}
this.startTime = System.currentTimeMillis();
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
canvas.save();
drawCustomLine(canvas);
canvas.restore();
elapsedTime = System.currentTimeMillis() - startTime;
if (elapsedTime < animationDuration) {
this.postInvalidateDelayed(1000 / framesPerSecond);
} else {
Log.e("Rido", "BiTTİ");
}
}
private void drawCustomLine(Canvas canvas) {
if (windList == null || windList.getWindDatas() == null || windList.getWindDatas().size() == 0) {
return;
}
for (int i = 0; i < windList.getWindDatas().size(); i++) {
LatLng firstBorderPoint = new LatLng(windList.getWindDatas().get(i).getLat(), windList.getWindDatas().get(i).getLon());
Point firstScreenPoint = googleMap.getProjection().toScreenLocation(firstBorderPoint);
aci = 90 - windList.getWindDatas().get(i).getDri();
int uz = 25;
int x2 = firstScreenPoint.x + (int) (uz * Math.cos(aci * Math.PI / 180));
int y2 = firstScreenPoint.y - (int) (uz * Math.sin(aci * Math.PI / 180));
Matrix matrix = new Matrix();
matrix.setScale(1, 1);
matrix.postTranslate((firstScreenPoint.x - x2) * elapsedTime / 5000,
(firstScreenPoint.y - y2) * elapsedTime / 5000);
canvas.setMatrix(matrix);
canvas.drawLine(firstScreenPoint.x, firstScreenPoint.y, x2, y2, getPaint(windList.getWindDatas().get(i)));
}
}
private int setPathColor(double speed) {
if (speed > 0 && speed < 5) {
return Color.GREEN;
} else if (speed > 5 && speed < 10) {
return Color.BLUE;
} else if (speed > 10 && speed < 20) {
return Color.YELLOW;
} else if (speed > 20) {
return Color.RED;
} else {
return Color.BLACK;
}
}
private Paint getPaint(WindDatasItem windDatasItem) {
paint = new Paint();
paint.setColor(setPathColor(windDatasItem.getSpd()));
paint.setStrokeWidth(3);
paint.setAntiAlias(true);
return paint;
}
}
what I want to write is actually made in a project called windjs