绘制,而不是一条线虚线(......)跟踪路径(________) [英] Drawing dotted (....)trail path instead of a line (________)

查看:117
本文介绍了绘制,而不是一条线虚线(......)跟踪路径(________)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在下面是我的code绘制在地图geopoints之间的路径。这工作完全正常。我想要实现的,而不是画线,显示这条道路的点(。),如iPhone。我希望它是这样的......... GP1 GP2,而不是在一个单一的直线状gp1_的 _ __ _ _gp2。

Now below is my code that draws path between geopoints in map. This works perfectly fine. What I'm trying to implement is instead of drawing a line,display this path with the dots(.) as in iPhone. I want it to be like this gp1.........gp2 instead of drawing in a single straight line like gp1______gp2.

我已经尝试了几乎所有这样做的选项,但仍没有这方面的成功,任何一个可以帮助我解决这个?

I have tried almost all the options for doing this but still no success on this, any one can help me solving this?

private void drawPath(List geoPoints, int color) {
    List overlays = objMapView.getOverlays();
    int loopcount = geoPoints.size() - 1;
    for (int i = 0; i < loopcount; i++) {
        GeoPoint p1 = (GeoPoint) geoPoints.get(i);
        GeoPoint p2 = (GeoPoint) geoPoints.get(i + 1);
        MyPathOverLay p = null;
        /**** Marking the start and end of the trailpath ****/
        if (i == 0) {
            Bitmap bmp = BitmapFactory.decodeResource(this.getResources(),R.drawable.greenflag);
            p = new MyPathOverLay(p1, p2, 0xFFFF0000, true, false, bmp);
        } else if (i == loopcount - 1) {
            Bitmap bmp = BitmapFactory.decodeResource(this.getResources(),R.drawable.redflag);
            p = new MyPathOverLay(p1, p2, 0xFFFF0000, false, true, bmp);
        } else {
            p = new MyPathOverLay(p1, p2, 0xFFFF0000, false, false, null);
        }
        overlays.add(p);
    }
}



public class MyPathOverLay extends Overlay {

private GeoPoint gp1;
private GeoPoint gp2;
private int color;
Boolean  isFirstPOI;
Boolean isLastPOI;
AudioMap audioMap;
Bitmap bmp;

public MyPathOverLay(GeoPoint gp1, GeoPoint gp2, int color,Boolean first, Boolean last,Bitmap bitMap) {
    this.gp1 = gp1;
    this.gp2 = gp2;
    this.color = color;
    this.isFirstPOI= first;
    this.isLastPOI = last;
    this.bmp = bitMap;
}

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    Projection projection = mapView.getProjection();
    Paint paint = new Paint();
    Point point = new Point();
    projection.toPixels(gp1, point);
    paint.setColor(color);
    Point point2 = new Point();
    projection.toPixels(gp2, point2);
    paint.setStrokeWidth(5);
    paint.setAlpha(120);
    canvas.drawLine(point.x, point.y, point2.x, point2.y, paint);
  //---translate the GeoPoint to screen pixels---
    Point screenPts = new Point();
    mapView.getProjection().toPixels(gp1, screenPts);
    //---translate the GeoPoint to screen pixels---
    Point screenPts1 = new Point();
    mapView.getProjection().toPixels(gp2, screenPts1);
    if(isFirstPOI == true){
            canvas.drawBitmap(bmp,screenPts.x-20,screenPts.y-40, null);  
    }
    else if(isLastPOI == true) {
            canvas.drawBitmap(bmp,screenPts1.x-20,screenPts1.y-35, null);  
   }
    super.draw(canvas, mapView, shadow);
}

}

推荐答案

感谢这家伙,我提到这个例子中,它是为我工作。

Thanks to this guy, I referred this example and it is working for me.

如何使一个点/虚线在Android的?

只需要添加这些2行,

    paint.setPathEffect(new DashPathEffect(new float[] {10,10}, 5));
    canvas.drawLine(point.x, point.y, point2.x, point2.y, paint);

我设置之后,

after I set,

    paint.setAlpha(120); 

@Frankenstein,谢谢

@Frankenstein, thank you

这篇关于绘制,而不是一条线虚线(......)跟踪路径(________)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆