代码之家  ›  专栏  ›  技术社区  ›  Soumya Simanta

在地图上绘制给定一组点的空多边形(Android 2.1)

  •  2
  • Soumya Simanta  · 技术社区  · 14 年前

    n 我想画一个点 n-sided 使用这些点的多边形。

    我试过使用android.graphics.path(请看下面)。

    Path path = new Path();
    Vertex currVtx;
    
    for (int j = 0; j < vertices.size(); j++) {
     currVtx = vertices.get(j);
    
     if (!currVtx.hasLatLong())
      continue;
    
     Point currentScreenPoint = getScreenPointFromGeoPoint(
       currVtx, mapview);
     if (j == 0)
      path.moveTo(currentScreenPoint.x, currentScreenPoint.y); 
              // vertex.
     else
      path.lineTo(currentScreenPoint.x, currentScreenPoint.y);
    
    }
    

    现在我用这个代码得到了一个实心多边形(用画布的颜色填充)。有没有办法得到一个未填充的多边形。有一种替代方法 android.graphics.Path

    1 回复  |  直到 14 年前
        1
  •  8
  •   Mark    14 年前

    定义绘制对象:

    Paint mPaint = new Paint();
    mPaint.setStrokeWidth(2);  //2 pixel line width
    mPaint.setColor(0xFF097286); //tealish with no transparency
    mPaint.setStyle(Paint.Style.STROKE); //stroked, aka a line with no fill
    mPaint.setAntiAlias(true);  // no jagged edges, etc.
    

    然后绘制路径:

    yourCanvas.drawPath(path,mPaint);