7

I have an imageView with width:match_parent and height:wrap_content. I want the image with full width and keep the ratio for the height.

I follow this link (https://github.com/nostra13/Android-Universal-Image-Loader/pull/62) who say to set adjustviewbounds and center_crop on my imageView and set imageScaleType to ImageScaleType.EXACTLY_STRETCHED.

So i do that :

DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
            .cacheInMemory()
            .cacheOnDisc()
            .showImageForEmptyUri(R.drawable.cache_waiting)
            .showImageOnFail(R.drawable.cache_waiting)
            .showStubImage(R.drawable.cache_waiting)
            .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
            .build();

            setAdjustViewBounds(true);
            setScaleType(ScaleType.CENTER_CROP);
            ImageLoader.getInstance().displayImage(img.getUrl(), this,defaultOptions);

With this code, most of ImageView are white. The logcat tell me the bitmap is too large (2560,1120). How can I keep the ratio of images with UIL.

Thanks,

FUBUs
  • 617
  • 5
  • 9
  • In what place of `ImageView` did you put aforementioned code? – nostra13 Jun 03 '13 at 17:51
  • I put this code in a build method in my ImageView. This build method is called by the fragment for example during the creation of this fragment. – FUBUs Jun 04 '13 at 06:57
  • I think `CENTER_CROP` isn't right scale type for you. Use default scale type and then maybe it prevent "too large Bitmap" issue. – nostra13 Jun 04 '13 at 18:04

2 Answers2

2

I also config as you. But ImageView should :

<ImageView
    android:id="@+id/thumb_item"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter" />
Hayboy
  • 21
  • 2
0

In ImageView set android:scaleType="centerInside" and see result if its not working then set android:scaleType="centerCrop"

see explanation in this link

https://github.com/nostra13/Android-Universal-Image-Loader/blob/master/library/src/com/nostra13/universalimageloader/core/assist/ViewScaleType.java

HemangNirmal
  • 621
  • 1
  • 8
  • 24