如何在 Glide with Animation 中加载图像

Ama*_*rai 5 android android-animation android-recyclerview android-glide

我正在使用 glide 从服务器图像加载图像,它突然显示,没有任何动画。我需要显示带有淡入淡出动画的图像,请给我一些建议。

sud*_*007 12

您必须transitions()在 GLIDE 构建器调用中使用 API。您可以通过以下两种方法来实现这一目标。

1)通过使用转换API:官方文档

GlideApp  
.with(context)
.load(....)
.transition(DrawableTransitionOptions.withCrossFade()) //Here a fading animation
.into(....);
Run Code Online (Sandbox Code Playgroud)

2) 通过创建用户tudorTransitionFactory的SOF答案

 GlideApp.with(this)
  .load(url)
  .transition(DrawableTransitionOptions.with(Your_custom_factory))
  .into(image)
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助