Android 滑动-添加过渡渐变会导致占位符调整大小

Android 滑动-添加过渡渐变会导致占位符调整大小,android,android-glide,Android,Android Glide,当将Glide与占位符一起使用,并使用过渡crossfade时,会导致占位符产生不需要的大小调整效果 在layerlist drawable中,占位符的大小应为50dp 使用crossFade(): 没有交叉褪色(): 持证人: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android=

当将Glide与占位符一起使用,并使用过渡crossfade时,会导致占位符产生不需要的大小调整效果

在layerlist drawable中,占位符的大小应为50dp

使用
crossFade()

没有
交叉褪色()

持证人:

<?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>

回收器适配器:

持证人:


占位符:

如果你不希望你的代码> IVIEVIEW 根据你正在加载的图像使用GLIDE来调整大小,你可以考虑采用下面的方法。 在

ViewHolder
的布局xml文件中设置
ImageView
的固定高度

<?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="50dp"
        android:adjustViewBounds="true"
        app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
然后在转换后应用这些选项

Glide.with(this)
  .load(itemList.get(i))
  .transition(DrawableTransitionOptions.withCrossFade())
  .apply(requestOptions)
  .into(holder.imageView);

嘿,感谢您的回复,但我需要调整图像的大小,因此我将图像
layout\u height
设置为
wrap\u content
,因为如果它是比固定高度小的图像,则会有空白。另外,添加固定高度并不能解决转换占位符大小调整问题。长话短说:。我还没有找到解决这个问题的办法。他还写道,他的公关解决了这个问题,但这不是你有任何黑客解决方案吗?我试图让它像imgur专辑一样。不幸的是,我没有。否则我会把它贴出来的。我看到的唯一方法是使用
TransitionFactory
实现自己的转换,但这需要时间。你也可以试着联系公关的作者,也许他知道一些可以帮助你的东西
<?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="50dp"
        android:adjustViewBounds="true"
        app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
RequestOptions requestOptions = new RequestOptions();
requestOptions.placeholder(R.drawable.ic_altered_placeholder);
requestOptions.error(R.drawable.error);
requestOptions.fitCenter();
Glide.with(this)
  .load(itemList.get(i))
  .transition(DrawableTransitionOptions.withCrossFade())
  .apply(requestOptions)
  .into(holder.imageView);