Android Java 处理程序 post 循环中每个记录的延迟

Android Java handler post delay at each records in loop

我在尝试像 Android Java 中的 setTimeout() 这样的动画时遇到了一些问题。我有一个几何图形列表,我想一次将它们绘制到地图上:

public void getDirection(Event eventModel, final Context context) {
    String eventX = eventModel.getEventX();
    String eventY = eventModel.getEventY();

    //Code to get data geometry data from API and store in pathGeometries       
    final Drawable d = EventDrawableImage.resizeCurrentLocImage("current_loc",
            context);
    for (int iii = 0; iii < pathGeometries.size(); iii++) {
        final int counter = iii ;
            EventDetail.handler.postDelayed(new Runnable()
            {
                private long time = 0;
                public void run()
                {
                    time += 1000;
                    EventDetail.handler.postDelayed(this, 1000);

                    moveNext(pathGeometries.get(counter).getX(),
                            pathGeometries.get(counter).getY(), 0, d);
                }
            }, 1000); 
    }
}

public static void moveNext(double coordx, double coordy, int k, Drawable d){
    //EventMain.mMapView.removeAll();

    // Set center
    Point p = new Point(coordx, coordy);
    EventMain.mMapView.zoomToResolution(p, 1);

    // Add marker
    PictureMarkerSymbol graphicIcon;
    graphicIcon = new PictureMarkerSymbol(d);
    Symbol symbol = graphicIcon;
    HashMap<String, Object> attrMap = new HashMap<String, Object>();
    attrMap.put("currentLoc", "User Current location");

    EventMain.graphicsLayer.addGraphic(new Graphic(p, symbol, attrMap));     
}

我现在遇到的问题是从 pathGeometries 传递到 moveNext() 的每个点,在移动到另一个点之前它不会保持 20 秒。相反,它只是一直循环直到结束而不在每个点停止。

有什么想法吗?提前致谢。

不确定我是否理解正确的意图,但尝试这样的事情:

long time = 0;
for (int iii = 0; iii < pathGeometries.size(); iii++) {
    final int counter = iii;
    time += 1000;
    EventDetail.handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            moveNext(pathGeometries.get(counter).getX(),
                    pathGeometries.get(counter).getY(), 0, d);
        }
    }, time);
}

也许循环并使用循环索引来构建延迟时间。

for (int iii = 0; iii < pathGeometries.size(); iii++) {
            EventDetail.handler.postDelayed(new Runnable()
            {
                public void run()
                {
                    moveNext(pathGeometries.get(counter).getX(),
                            pathGeometries.get(counter).getY(), 0, d);
                }
            }, 1000 *(iii+1)); 
    }