4

I guess the title already says what I want to do:

I have an ImageView, when the image to display has been loaded from the web (with UIL) I want to

a. have the image scaled down to fit into the ImageView if the image is larger than the ImageView

b. not scale the image up but rather display in it's original size when the Image is smaller than the ImageView

Bot are no problem with

android:scaleType="fitCenter"

for a. and

android:scaleType="center"

for b.

Is there any possibility to combine the two? Will my only option be to 'manually' compare the size of the ImageView and the size of the loaded BitMap with each other and set the scaleType accordingly?

EDIT: This is my UIL config:

public static final DisplayImageOptions uiloptions = new DisplayImageOptions.Builder()
        .resetViewBeforeLoading(true)
        .bitmapConfig(Bitmap.Config.RGB_565)
        .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
        .cacheInMemory(true)
        .cacheOnDisk(true)
        .build();

imageLoaderConfiguration = new ImageLoaderConfiguration.Builder(this)
        .threadPoolSize(2)
        .defaultDisplayImageOptions(Values.uiloptions).build();
7
  • Try use image loading library with various option achieved ur requirement : square.github.io/picasso and github.com/nostra13/Android-Universal-Image-Loader. May 15, 2015 at 12:15
  • i guess UIL handles this on basis of size of imageview you dont have to do anything extra
    – amodkanthe
    May 15, 2015 at 12:15
  • @apk Currently it doesn't it scales my small images up. Added my UIL config.
    – fweigl
    May 15, 2015 at 12:18
  • @Ascorbin share your imageview xml dont add wrap_content specify width and height you want it will work
    – amodkanthe
    May 15, 2015 at 12:20
  • @apk The imageView is just a standard ImageView with width = match_parent and the height match_parent.
    – fweigl
    May 15, 2015 at 12:21

1 Answer 1

0

Try to use this attribute:

android:scaleType="centerInside" 

Here is a link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.