How do I make a background image fit the view but keep its aspect ratio when using <bitmap /> as a background drawable XML?
None of <bitmap>‘s android:gravity values gives the desired effect.
How do I make a background image fit the view but keep its aspect
Share
It is impossible to achieve manipulating background attribute within xml-files only. There are two options:
You cut/scale the bitmap programmatically with
Bitmap.createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)and set it as someView‘s background.You use
ImageViewinstead of background placing it as the first layout’s element and specifyandroid:scaleTypeattribute for it: