简体   繁体   中英

BitmapDrawable does not respect scaleType on view

I want to display an image synchronously on a view, and I am using Universal Image Loader:

https://github.com/nostra13/Android-Universal-Image-Loader

On async call the library displays the image properly. Though, doing something like this:

myImageView.setBackground(new BitmapDrawable(getApplicationContext().getResources(), ImageLoader.getInstance().loadImageSync("path/to/image")));

The image gets displayed, ignoring my scaleType on layout, which is centerCrop. I want to do this without having to process the image which would increase the load time. I have been searching Google for 4 hours now without luck. I landed on some threads in here but they are not helpful.

Thank you for your time.

You should use setImageDrawable() instead of setBackground() . Using the image as a background will always ignore the scale type.

myImageView.setImageDrawable(new BitmapDrawable(getApplicationContext().getResources(), ImageLoader.getInstance().loadImageSync("path/to/image")));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM