【问题标题】:Need bordered circle with different color around user's location需要在用户位置周围有不同颜色的带边框的圆圈
【发布时间】:2013-06-12 06:15:39
【问题描述】:

如果我的问题太简单,请道歉。

我正在开发一个 android 应用程序,在该应用程序中我在地图中显示用户位置。我还在用户点周围显示一个圆圈。

我在 ItemizedOverlay 中的代码是:

    public void setGeoPoints(GeoPoint theGeoPoints, int theCircleRadius) 
    {
        this.itsGeoPoints = theGeoPoints;
        itsPaint = new Paint();
        itsPaint.setARGB(10, 0, 0, 205);
        this.itsCircleRadius = theCircleRadius;
    }

    @Override
    public void draw(Canvas theCanvas, MapView theMapView, boolean shadow) 
    {
        super.draw(theCanvas, theMapView, shadow);
        Point pt = theMapView.getProjection().toPixels(itsGeoPoints, null);
        float projectedRadius = theMapView.getProjection().metersToEquatorPixels(itsCircleRadius);
        theCanvas.drawCircle(pt.x, pt.y, projectedRadius, itsPaint);
    }

使用上面的代码,我在用户位置周围完美地得到了一个蓝色圆圈。

现在,我需要为圆圈设置不同颜色的边框。也就是说,一个带有粗边框的圆圈(不同的颜色)。

请在这方面提供任何帮助。

谢谢。

【问题讨论】:

    标签: android android-layout android-maps android-maps-v2


    【解决方案1】:

    您需要创建一个单独的Paint 对象,并使用Paint.setStyle 和不同的颜色设置STROKE 样式。

    当您使用这个新的Paint 再次调用drawCircle

    【讨论】:

      【解决方案2】:

      感谢 MaciejGórski!

          public void setGeoPoints(GeoPoint theGeoPoints, int theCircleRadius) 
          {
              this.itsGeoPoints = theGeoPoints;
      
              itsPaint1 = new Paint();
              itsPaint1.setARGB(150, 0, 0, 255);
              itsPaint1.setStyle(Style.STROKE);
      
              itsPaint2 = new Paint();
              itsPaint2.setStyle(Style.FILL);
              itsPaint2.setARGB(5, 0, 0, 200);
              this.itsCircleRadius = theCircleRadius;
          }
      
          @Override
          public void draw(Canvas theCanvas, MapView theMapView, boolean shadow) 
          {
              super.draw(theCanvas, theMapView, shadow);
      
              Point pt = theMapView.getProjection().toPixels(itsGeoPoints, null);
              float projectedRadius = theMapView.getProjection().metersToEquatorPixels(itsCircleRadius);
      
              theCanvas.drawCircle(pt.x, pt.y, projectedRadius, itsPaint1);
              theCanvas.drawCircle(pt.x, pt.y, projectedRadius, itsPaint2);
          }
      

      【讨论】:

        猜你喜欢
        • 2016-09-09
        • 2017-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-18
        相关资源
        最近更新 更多