richbl richbl - 3 months ago 22
Android Question

How to make MapView object transparent (alpha)?

All,

I have a need to display information on a MapView object. No problems there.

The issue is that there are times when the MapView object displays map details that visually compete with my overlay data.

So, what I'd like to do is provide a way to "scale back" the MapView object visually by using an alpha channel.

Can an alpha value get applied to a MapView object? If so, how?

Alternatively, I was thinking that perhaps a separate all black overlay might provide the same results. Scale the alpha of this overlay and I might end up with the same overall effect.

Insight please.

Thanks.

Rich

Answer

Are you sure you want to do this? It might be better to revisit your overlay's graphic design... simply giving them a thicker border might be a cheap solution to the problem.

First suggestion would be to subclass MapView and override dispatchDraw() with something like this:

@Override protected void dispatchDraw(Canvas canvas) {

  // Firstly let MapView draw
  super.dispatchDraw(canvas);

  // Draw a translucent fill on top of it
  canvas.drawColor(0x7FFFFFFF);

  // TODO: Draw my overlay
}
Comments