Universal Image Loader keep ratio
Asked Answered
T

2

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,

Thickness answered 3/6, 2013 at 15:20 Comment(3)
In what place of ImageView did you put aforementioned code?Better
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.Thickness
I think CENTER_CROP isn't right scale type for you. Use default scale type and then maybe it prevent "too large Bitmap" issue.Better
T
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" />
Tolliver answered 26/12, 2014 at 3:56 Comment(0)
I
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

Inconsequent answered 30/3, 2014 at 15:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.