Android: ImageView with centerCrop scale has not the same behavior on 4.1.1 and 4.4.4 (Android SDK)

168 views Asked by At

I use this layout to show an image in my RecyclerView:

<ImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/picture"
    android:layout_width="match_parent"
    android:layout_height="match_parent"    
    android:scaleType="centerCrop" />

I load a picture with Glide library like that:

Glide.with(context)
    .load(my_url)
    .skipMemoryCache(true)
    .placeholder(R.drawable.default_medium_wide_picture)
    .crossFade()
    .into(contentHolder.mImageView);

The height of ImageView is computed during the viewholder creation according the width screen:

DisplayMetrics metrics = MyApplication.getInstance().getResources().getDisplayMetrics();
imageView.getLayoutParams().height = Math.round(metrics.widthPixels * Defines.IMAGE_HEIGHT_RATIO);

The result is perfect on 4.4.4 Android version:

enter image description here

But on 4.1.1 Android version the result expected is bad:

enter image description here

Thanks by advance guys for your help!

1

There are 1 answers

0
Reaz Murshed On

You just can use centerCrop of Glide and remove the calculation of height based on width.

Glide.with(context)
    .load(my_url)
    .skipMemoryCache(true)
    .placeholder(R.drawable.default_medium_wide_picture)
    .crossFade()
    .centerCrop() // Use centerCrop here
    .into(contentHolder.mImageView);