Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Universal Image Loader keep ratio

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,

like image 347
FUBUs Avatar asked Jun 03 '13 15:06

FUBUs


1 Answers

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" />
like image 141
Hayboy Avatar answered Oct 30 '22 04:10

Hayboy