android maps v2 polygon transparency

北城以北 提交于 2019-12-07 05:15:27

问题


I'm using Google Maps v2 API for android and I don't manage to control the transparency of the fillColor. I would like to be able to see the map under a filled polygon. Is there a way to do that ?

Thanks for any help !


回答1:


Well, let me describe how standard 4 bytes color is encoded:

Standard pixel color consists of 4 bytes:

  • A (alpha channel) - 0-255 (0 - fully transparent, 255 - fully opaque)
  • R (red color channel) - 0-255
  • G (green color channel) - 0-255
  • B (blue color channel) - 0-255

Each channel represents the saturation of particular color part. So if we need to create fully opaque red color, we need to specify following channel values:

  • 255,255,0,0

If we want to make it half-transparent, we need to divide alpha channel value by 2 (255/2 = 127):

  • 127,255,0,0

So let's go back to the android. In Android in most cases you can specify color by specifying it's hex value:

polygon.setFillColor(0xFF00FF00); //not transparent green color

In hex every channel can be specified by 2 hex digits:

  • A(FF)
  • R(00)
  • G(FF)
  • B(00)

If you want to make this color half-transparent, you need to divide FF by 2:

0xFF/2 = 0x7F //the same as 255/2 = 127

polygon.setFillColor(0x7F00FF00); //half-transparent green color

So basically what you need to do - is to play with alpha channel value in order to get transparency you are looking for




回答2:


 cir=map.addCircle(new CircleOptions().center(new LatLng(10.938341, 76.9548734))
.radius(150)
.strokeColor(Color.rgb(0, 50, 100))
.strokeWidth(5)
.fillColor(Color.argb(20, 50, 0, 255)) 
.zIndex(55));

 cir.setVisible(true);



回答3:


Basically what worked for Me is :

  polygon = mGoogleMap.addPolygon(new PolygonOptions().
        addAll(points)
            .fillColor(0x33FF0000)
             .strokeColor(Color.RED)
               .strokeWidth(3))


来源:https://stackoverflow.com/questions/14326482/android-maps-v2-polygon-transparency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!