我正在使用我的MapView addView()方法向其添加动画视图。
当我这样做时,我的MapView中已经有了一些OverlayItems。
当调用addView()方法时,我的所有标记都在消失......
任何想法为什么?
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
app.setMapActivity((Map)context);
if (!isAnimating)
{
if (isNewMarkers(canvas, mapView, shadow))
isAnimating = true;
else
finishDraw(canvas, mapView, shadow);
}
}
private boolean isNewMarkers(Canvas canvas, MapView mapView, boolean shadow) {
boolean isNewMarkers = false;
synchronized (newMarkers)
{
Iterator<OverlayItem> iterator = newMarkers.iterator();
while (iterator.hasNext())
{
OverlayItem overlayItem = iterator.next();
isNewMarkers = true;
animateMarker(canvas, mapView, shadow, overlayItem.getMarker(0), overlayItem.getPoint(),!iterator.hasNext());
}
}
fullMapOverlays.addAll(newMarkers);
newMarkers.clear();
populate();
return isNewMarkers;
}
private void animateMarker(Canvas canvas, MapView mapView, boolean shadow, Drawable marker, GeoPoint point, boolean setListener)
{
Animation animation = AnimationUtils.loadAnimation(app.getMainActivity(), R.anim.map_marker_animiation);
ImageView imageView = (ImageView) View.inflate(app.getMainActivity(), R.layout.marker_animation, null);
imageView.setImageDrawable(marker);
//add view function
mapView.addView(imageView, 0, new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, point, MapView.LayoutParams.BOTTOM_CENTER));
if (setListener)
animation.setAnimationListener(new MarkerAnimationListener(canvas, mapView, shadow));
imageView.startAnimation(animation);
}
public void finishDraw(Canvas canvas, final MapView mapView, boolean shadow)
{
mapOverlays = createOverlayItems(mapView);
populate();
setLastFocusedIndex(-1);
super.draw(canvas, mapView, shadow);
if (mapView.getChildCount()>0)
{
mapView.post(new Runnable() {
@Override
public void run() {
mapView.removeAllViews();
}
});
}
}
private class MarkerAnimationListener implements AnimationListener
{
private MapView mapView;
private Canvas canvas;
private boolean shadow;
public MarkerAnimationListener(Canvas canvas, MapView mapView, boolean shadow)
{
this.mapView = mapView;
this.canvas = canvas;
this.shadow = shadow;
}
@Override
public void onAnimationEnd(Animation animation) {
isAnimating = false;
finishDraw(canvas, mapView, shadow);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
}
}