views:

42

answers:

1

I have the following custom view:

alt text

This I have achieved by using the Canvas' drawArc() method. However, with this drawArc() method I cannot limit the arc's inner radius.

What I'd like to have is something like this:

alt text

where there is only an outer ring left.

What I need is an drawArc() function where I can set the inner radius of the arc. Anyone an idea how to do that?

(BTW, overpainting the inner area doesn't work, because it needs to be transparent. Painting an inner circle with Color.TRANSPARENT after painting the red and blue cones doesn't remove the old color. It just puts another layer on top, which is transparent and through which I can still see the red and blue)

+2  A: 

You can paint over the inner area using the PorterDuff xfermode called "Clear." This will erase pixels.

Romain Guy
That's a possible solution. But what to do for the case, that there's already something drawn in the inner circle, which I don't want to get overpainted and neither to I want to erase the pixels and redraw it?
znq
Draw the circle in an offscreen ARGB8888 bitmap, do the clear there, then draw the bitmap onto your Canvas. And that way you also don't have to redraw the circle every time.
Romain Guy
So, after looking into how to actually do this, I'm a bit lost: is an ARGB8888 bitmap a "normal" Bitmap http://goo.gl/ygTn - and how do I get the same drawing functions as I do with Canvas?
znq
Update: I figured out that I can actually do it this wayBitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);Canvas c = new Canvas(bm);and then draw on the Canvas, which will then write the actual pixels on the Bitmap.
znq