Why glide center crop didn't work correctly?

29 views Asked by At

I use

Glide.with(root.context)
      .load(url)
      .placeholder(R.drawable.product)
      .error(R.drawable.product)
      .centerCrop()
      .into(bindingUsersMedia.imageViewMedia)

and imageView code

 <ImageView
        android:id="@+id/imageViewMedia"
        android:layout_width="68dp"
        android:layout_height="68dp"
        android:scaleType="centerCrop"
        tools:srcCompat="@drawable/product_placeholder" />

My image still look like rectangle, but i need that i need squaery(68x68) What am I doing wrong? *glide version - 4.11.0

1

There are 1 answers

2
willford On

A few questions for you:

  1. Where do you want to see the desirable result? Whether from the "Design" tab in Android Studio's XML Editor or from Emulator/Physical device? As for "Design" tab keep attention to your image you use as a placeholder here: tools:srcCompat="@drawable/product_placeholder"? It might have some unnecessary spaces that can distort the appearance.
  2. Similar question to .load(url). Does it loads an appropriate image you want? Isn't it transparent like ".png" one? Pay attention to cache, as you can have the same URL address but it can pull the outdated version with the same URL.
  3. Again for another one: .error(R.drawable.product). What image exists behind this resource address?
  4. Keep in mind that Glide will respect the view's scale type in XML as well. And the value in android:scaleType="centerCrop" attribute of your ImageView would lead Glide to also use centerCrop as a scale type, so you don't need it in your Java/Kotlin code or vice versa: you can remove it from XML and leave in your code.