Axonshi 123 Axonshi 123 - 3 months ago 9
Android Question

Drawable gets stretched to fit the view

I'm trying to set a Bitmap Drawable as the background like this,

root.setBackground(bitmapDrawable);
, I've set its bounds to be 1080 wide by 300 high, but it keeps stretching to fit the entire background. Is there any way to avoid this? This is how i created the
BitmapDrawable
BitmapDrawable bitmapDrawable= new BitmapDrawable(getResources(), bmp1);

Answer

I believe the default Gravity of a BitmapDrawable is FILL. Try setting the Gravity to CENTER:

bitmapDrawable.setGravity(Gravity.CENTER);