I have a LayerDrawable, which should display 5 Bitmaps. 1 background and 4 Icons (which can be different for every LayerDrawable) like a Grid. Unfortunately these Icons don't have the same width than height. My Problem is to resize them, while keeping their ratio and place them inside their Position (1-4 Icons, 5 background):
==================
| | | |
| 1 | | 2 |
|------.5 .------|
|------. .------|
| 3 | | 4 |
| | | |
==================
If I resize these Bitmaps, give them Gravity.CENTER
they won't fit anymore inside the Bounds of the Background Rectangle. If I leave Gravity.CENTER
they seem to get rescaled as soon as I call layerDrawable.setLayerInset(numlayer, left, top, right, bottom)
.
What is the right way to do it? How can I keep their ratio while placing them correctly?
What I also couldn't understand so far is why getIntrinsicWidth/Height from BitmapDrawable is returning something else (smaller) than getWidth/Height from original Bitmap.
What I tried:
1. Getting them from XML, putting a 'dummy-drawable' inside and replace it with result described above.
2. Create LayerDrawable inside my Program passing all drawables inside. It seems that setLayerInset has no affect, or I only see the Background (which was Element 0 inside my Drawable Array)
3. Extending LayerDrawable and try to keep track on anything myself without reasonable results
The BitmapDrawable
, dy default, fills its bounds with the given Bitmap
. If you start using Gravity
, the Bitmap
will be position according to the given Gravity
. I suppose in your case, the best choice is to create your own Drawable
.
Concerning the getIntrinsic[Height|Width] methods, they return the actual size of your underlying Bitmap
which may be different if the system resized it it while loading it (an hdpi image loaded on an mdpi screen for instance).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With