Android: Scale whole image to fit ImageView and keep aspect ratio


It took me a while to figure out, but it's not ScaleType.FIT_XY that does the trick but FIT_CENTER.

FIT_XY will stretch both width and height to fit the ImageView.

Remember to use ImageView.setImageDrawable() or setImageBitmap() rather than setBackgroundDrawable().

Source: Android: Scale a Drawable or background image?


Post a Comment

Leave your thoughts ...
If you are having trouble with copy/pasting in comments, you need to sign in or click 'Preview'. For more information about this Firefox bug, see here.

Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog