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

2023-09-05 10:25:39 作者:我是流氓我怕谁

我已经设置了 N 点,我想提请使用这些点 n边多边形。

I've set of n points and I want to draw a n-sided polygon using these points.

我试图用android.graphics.path(请参见下文)。

I tried using android.graphics.path (please see below).

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);

}

目前,我得到一个固体(填充画布的颜色)的多边形与此code。有没有一种方法,我可以得到一个未填充的多边形。有一个替代 android.graphics.Path

Currently I'm getting a solid (filled with the color of the canvas) polygon with this code. Is there a way that I can get an unfilled polygon. There is an alternative to android.graphics.Path

感谢。

推荐答案

定义绘制对象:

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.

然后绘制路径有:

Then draw the path with:

yourCanvas.drawPath(path,mPaint);

您可以看一下油漆文档,但也有选项吨来控制它的绘制。

You can look up the paint documentation but there are tons of options to control how its drawn.