I have a LayerDrawable that should display 5 bitmaps. 1 background and 4 icons (which may be different for each LayerDrawable), like a grid. Unfortunately, these icons do not have the same width as the height. My problem is to resize them, keeping their ratio and putting them in their position (1-4 icons, 5 backgrounds):
==================
| | | |
| 1 | | 2 |
|------.5 .------|
|------. .------|
| 3 | | 4 |
| | | |
==================
If I resized these bitmaps, give them Gravity.CENTERthey will no longer fit inside the borders of the background rectangle. If I leave Gravity.CENTER, they seem to be rescaled as soon as I call layerDrawable.setLayerInset(numlayer, left, top, right, bottom). What is the right way to do this? How can I keep their ratio when placed correctly? What I also could not understand so far is why getIntrinsicWidth / Height from BitmapDrawable returns something else (less) than getWidth / Height from the original bitmap.
What I tried:
1. Having received them from XML, having placed in itself a "dummy drawing" and replacing it with the result described above. 2. Create a LayerDrawable inside my Program, passing all the drawings inside. It seems that setLayerInset has no effect, or I only see Background (which was the 0 element inside my Drawable Array)
3. The LayerDrawable extension and attempt to track anything on my own without reasonable results.
source
share