Search code examples
androidcolorsimageviewfill

Fill ImageView With Colors in android


I run into a difficulty in my application.

I have an ImageView that represents a chemistry flask. I would like that when I click on buttons of various colors, the ImageView is filled with the said color.

I would like a stack of each separate color but if you have a solution for mixing every color (maybe in a gradient ? it will be ok too) I would have 12 colors at the end in total

The problem is that I don't know how to do it.

Anyone have an idea?

Example:

Start

I click on a button which corresponds to the color blue :

enter image description here

Then I click on a button which corresponds to the color red:

enter image description here


Solution

  • I would go with Canvas. You can first draw solution, and then add drawing of the flask on top of that.

    First, I'd measure the height of the flask in pixels so that I'd be able to calculate how much pixels in height does 1 unit of volume take. After that, you can add separate solutions based on number of units and start drawing at the top of last one.

    Once you draw all the solutions, just draw image of flask on the same canvas.