Friday 23 October 2020

Glide - Adding transition crossfade causes placeholder to resize

When using Glide with a placeholder and using the transition crossfade, it causes it to have an unwanted resizing effect on the placeholder.

The size of the placeholder should be 50dp inside the layerlist drawable.

With crossFade():

https://www.youtube.com/watch?v=7FlCJDSwoAI

Without crossFade():

https://www.youtube.com/watch?v=vqZKZb-BKqE

Glide.with(context)
      .load(itemList.get(i))
      .apply(RequestOptions.fitCenterTransform())
      .placeholder(R.drawable.ic_altered_placeholder)
      .transition(DrawableTransitionOptions.withCrossFade())
      .into(holder.imageView);

Viewholder:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <ImageView
        android:id="@+id/vh_iv_album_single_picture"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

The drawable placeholder:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- needs the extra spacing otherwise the drawable will be too big -->
    <item android:drawable="@drawable/ic_black_album_placeholder"
        android:left="51dp" android:right="51dp" android:top="51dp" android:bottom="51dp" />
</layer-list>

Is there a fix for this issue?


Heres the code to replicate:

MainActivity: https://pastebin.com/3G7BMct3

RecyclerAdapter: https://pastebin.com/eX3T4w9s

Viewholder: https://pastebin.com/Yvri5XFf

Placeholder: https://pastebin.com/pKputgmG



from Glide - Adding transition crossfade causes placeholder to resize

No comments:

Post a Comment