0

enter image description here

I wanna create a custom view with three circle images view using native android. Now I can create one circle image view using CircleImageView from hdodenhof. I wonder if anyone can tell me which way is better to put three circles like the following pic. Thanks.

Jennifer He
  • 75
  • 1
  • 2
  • 10
  • Can you please describe an actual problem? Or post code that don't work? – Michael Spitsin Jul 17 '16 at 18:26
  • @MichaelSpitsin Thanks for your response. I only have code to create circle image view which works fine. Now I am thinking to create three circle images view. One way I am thinking is to use relativelayout. But I dont know if there is better way? – Jennifer He Jul 17 '16 at 18:33
  • The answer is "it depends". If you need that circle will be three independent entities then yes, three views are normal solution. You can choose FrameLayout or CustomLayout to provide x,y positioning. If you need 3 static circles or circles with some simple animation then you can create 3 drawables and put them into one view. This will optimize performance as views are very heavy and drawables are not – Michael Spitsin Jul 17 '16 at 20:20

1 Answers1

0

You could, as you suggest, build a custom view from three CircleImageViews and an appropriate layout.

However, I suspect that you would have difficulty getting the circles to layout in the manner shown in your sample.

I'm fairly certain that this would be next to impossible with RelativeLayout, though you may be able to accomplish this with creative use of one of the other layouts.

Other options include:

  • Merge the 3 images in a graphics editor, and then create a custom view using that.

  • Merge the 3 images as above, and just use it in an ImageView

  • Create a custom view from a Canvas, and draw the images yourself, at the appropriate locations.

Which you do will probably depend on how you want the custom control to behave, including:

  • is any part of it to be animated?

  • are the 3 circles to be separately clickable?

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
  • Thanks for your response. I got one circle image view works. The next step is to group them as above. These 3 circles need to be separately clickable and then based on the click event, their background images will change. – Jennifer He Jul 17 '16 at 19:28
  • So, the pluses and minuses: - using ImageViews buys you ease of handling the clicks and changing the images, but may be difficult to lay out. - using a Canvas lets you arrange the images however you wish, but you have to handle hit-testing the circles yourself when the custom view is clicked, and you have to handle drawing yourself. – GreyBeardedGeek Jul 17 '16 at 20:35