0

I have an image view with a (not really) complex background. The background is to be the composition of three circles, each with different dynamically set colors.

  • one circle, the largest, is actually a perimeter (i.e. stroke)

  • one circle, the second largest, is concentric with the perimetric circle

  • one circle, the smallest, sits at the base of the other two circles (so that it is not concentric).

I successfully create the 3-circle background using layer-list. But the problem is that I am not able to change the colors in the layer-list dynamically. Changing the color of these circles is a crucial part of the design.

So since my ImageView is part of a custom view anyway, I am now thinking of using the canvas in onDraw(Canvas canvas) to create my three circles and set them as the background of the ImageView. However, the problem with this approach is that I don't know how to set my composite image (the three circles) as the background of my ImageView.

Any snippet of code solving this problem is greatly appreciated.

Cote Mounyo
  • 13,817
  • 23
  • 66
  • 87
  • 1
    If the imageview is the part of some custom view you are creating, and you are drawing to the custom view through onDraw(). Why do you still need the ImageView? – josh527 Jul 25 '13 at 23:03
  • Good question. There is actually an elaborate layout that I need to draw at dynamically determined axes (y-intercepts). So, instead of having a huge pile of code, I decided to draw that layout in xml and inflate it. Then in java do only the necessary coding to edit that template and draw it. – Cote Mounyo Jul 26 '13 at 00:05
  • Not sure if there is any certain way to set the drawn custom view as the background for your imageView, but perhaps you could bring the image view to the front. See this thread. http://stackoverflow.com/questions/10784655/android-set-a-view-to-be-on-top-of-items-drawn-with-canvas?rq=1 – josh527 Jul 26 '13 at 00:11
  • Can you post your code for working concentric circles? I'm actually having problems getting this to render correctly. – Sean Barbeau Dec 19 '14 at 15:39

0 Answers0