3

I use Fresco to load gif in a Recyclerview.

Here is my kotlin code:

fun loadResizeImage(uri: Uri, view: SimpleDraweeView, width: Int, height: Int) {
    val request = ImageRequestBuilder.newBuilderWithSource(uri)
            .setResizeOptions(ResizeOptions(width, height)).build()

val controller = Fresco.newDraweeControllerBuilder()
        .setOldController(view.controller)
        .setImageRequest(request)
        .build()
view.controller = controller

I don't play the gif, I just load it as a static image. But when I invoke notifydatasetchanged, the gif blinks. I have set the supportsChangeAnimations to false, and only the gif is blinking. Can anyone help me?

IAmInPLS
  • 4,051
  • 4
  • 24
  • 57
Allen Vork
  • 1,536
  • 3
  • 16
  • 29
  • you are resettting a controller.Can you avoid doing that if the controller uri has not changed?that should prevent the blinking. – Droidekas Apr 07 '16 at 12:05
  • i can set the uri as a tag to the view.if the tag equals to the uri,i just don't do the things in the block? – Allen Vork Apr 08 '16 at 06:45
  • i have tried this, but it doesn't work well.when i invoke notifydatasetchange, i find the tag is different from the uri – Allen Vork Apr 08 '16 at 07:14
  • 1
    Sorry.I just understood your sitaution.So notifyDatasetChanged triggers a complete redraw.Irrespective of the items being drawn previously or not.This will bring a flash in the sceen.Which will occur even for normal images loaded using fresco(not necessarily gifs),So using notifyItemChanged would be a better solution – Droidekas Apr 08 '16 at 12:25
  • That's right.I've done it and it works well.notifyDataSetChanged will invoke onCreateVIewHolder() which will create new views and the tag i set to the view is gone.But notifyItemChanged will retain the item of this position's identity so the tag is not cleared. – Allen Vork Apr 09 '16 at 05:39

1 Answers1

1

My solution is to set tag to the view, if the tag equals to the uri i won't reload the image. But I find when i invoke notifyDataSetChange, the tag i set to the view is changed.but when I invoke notifyItemChanged,it doesn't.I have no idea why the tag changed(i didn't scroll the RecyclerView).

Allen Vork
  • 1,536
  • 3
  • 16
  • 29