Jay
Jay

Reputation: 5084

Glide RoundedCornersTransformation not making any changes if scaleType is centerCrop

I am using Glide 4.3.0 and wasabeef/glide-transformations to add a corner radius the bottom left and right corners of my image view. The image is loaded but the transformation is not applied and I don't see any changes in the corners.

Here's my Glide transformation:

Glide.with(context)
    .load(message.imageUrl)
    .apply(bitmapTransform(new RoundedCornersTransformation(25, 0, RoundedCornersTransformation.CornerType.BOTTOM)))
    .into(aq.id(R.id.ivSingleImage).getImageView());

My imports are as follows:

import com.bumptech.glide.Glide;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import static com.bumptech.glide.request.RequestOptions.bitmapTransform;

The image is loaded but no transformation is applied. Is this implementation correct?

I also tried CornerType.BOTTOM_LEFT and CornerType.BOTTOM_RIGHT

EDIT

I noticed that this only occurs when the scaleType is set to centerCrop. If I remove that from the XML, it works but with 2 big spaces on left and right side of the image:

<ImageView
     android:id="@+id/ivSingleImage"
     android:layout_width="match_parent"
     android:layout_height="100dp"
     android:layout_marginRight="5dp"
     android:layout_weight="1"
     android:background="@color/white"
     android:scaleType="centerCrop" <!--Removing this works. But leaves two spaces on left and right sides-->
     android:layout_marginEnd="5dp" />

Referring to the update^, how can I have the image centerCrop and still have a rounded transformation?

Upvotes: 3

Views: 4687

Answers (1)

Jay
Jay

Reputation: 5084

Found the solution. Solution uses MultiTransformation and the CenterCrop transformations in glide-transformations library that I mentioned in the question.

Heres' the solution:

MultiTransformation multiLeft = new MultiTransformation(
     new CenterCrop(),
     new RoundedCornersTransformation(25, 0, RoundedCornersTransformation.CornerType.BOTTOM_LEFT));

Glide.with(context)
     .load(message.imageUrl)
     .apply(bitmapTransform(multiLeft))
     .into(aq.id(R.id.ivSingleImage).getImageView());

Using centerCrop in the scaleType attribute of the XML does not work with the Glide library transformations.

Upvotes: 15

Related Questions