I’m trying to display a LayerDrawable as an ImageButton image. All the layers must have different top values. such as top += 10;. For this I used setLayerInset with Drawable layer items but it stretched the images. I also tried with different parameters and it just displayed other stupid layouts.
After the setLayerInset attempt I used InsetDrawable, giving the top parameter its own constructor:
new InsetDrawable(resources.getDrawable(R.drawable.soldier), 0, layerTop, 0, 0);
this time, the tops look OK, but ImageButton displays a very small area of it.
Basic layout,
let say this is my image,
*---* | | | | ---
the layout should be,
*---* | | *---* | | *---* | | *---* | | | | ---
I set the
android:scaleType="fitStart"and changed the line as below and it is working like a charm.Now I have more questions,
First, as you can see I am creating a new instance for every layers. If I create only one
Drawableobject and set it to the every items of the array that will be used for creating theLayerDrawableand uselayerDrawable.setLayerInsetfunction to set the top and bottom properties, would it be more efficient.And the other one if the LayerDrawable object has more items bigger than the imageButton it still displays the images. Is there a setting such as CSS
overflow:hiddenor something?Thanks.