2

I have to create a custom view that extends LinearLayout.I have to draw an image on it.And some percent of it's area must be lighted, depending on the situation.That percent my be any integer between 0 to 100.For example some times,half of it,some times in about 30% and so on.

This image shows three probability lighted areas:

enter image description here

I decide to draw that image in onDraw() method.But I do not know how I can light some percent of area of that image?

I do not want to use Open GL.

hasanghaforian
  • 13,858
  • 11
  • 76
  • 167

1 Answers1

3

If you don't want to use OpenGL I would create two images - one not lighted and second one (on top of the first one) lighted. Both aligned properly so that you can see only the top image.

Now whenever you want to decrease lighted area, just crop (not simply resize) the top image according to your needs.

Here you can read of how to crop an image:

Crop Drawable to Square

android - How to cut some part of image and show it in imageview

It is - of course - duplicating a number of images to draw, but if you don't have a large amount of them it shouldn't be problem.

Community
  • 1
  • 1
Piotr Chojnacki
  • 6,837
  • 5
  • 34
  • 65