fresco icon indicating copy to clipboard operation
fresco copied to clipboard

frequent refresh listview..sometimes cause images flashing

Open lushan1314 opened this issue 11 years ago • 23 comments

my adapter getView was simple :

 mSimpleDrawee.setImageURI(Uri.parse(item.img));

frequent call the method of notifyDataSetChanged, sometimes page kept flashing...

It seems caused by frequent load(or decode) pictures.
How to avoid it ? thank you !

lushan1314 avatar Apr 23 '15 10:04 lushan1314

Can you upload a video? What format of images are you showing, and are they network, or local?

tyronen avatar Apr 24 '15 12:04 tyronen

it is difficult to reproduce... the images from network.

i will upload the video , when it's reproduced again..

thank you

lushan1314 avatar Apr 27 '15 08:04 lushan1314

2015050601

i found it again, when i call the mListView.notifyDataSetChanged();,the image kept flashing

please check the gif that i was upload.

thank you!

lushan1314 avatar May 06 '15 10:05 lushan1314

Can you show us a code snippet?

I also wonder why only one image is affected. What kind of image is it (gif, jpeg, etc)? Is it animated?

tyronen avatar May 08 '15 15:05 tyronen

This happens to me as well.

Here's my snippet of onBindViewHolder in RecyclerView Adapter:

ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(message.getImageUrl()))
                                .setPostprocessor(mTransformation)
                                .setResizeOptions(mResizeOptions)
                                .build();
DraweeController controller = Fresco.newDraweeControllerBuilder()
                                .setOldController(holder.imgAlbumArt.getController())
                                .setImageRequest(request)
                                .build();
holder.imgAlbumArt.setController(controller);

raylee4204 avatar May 11 '15 21:05 raylee4204

lushan1314 Did you solve this problem?

appdev avatar May 12 '15 01:05 appdev

@raylee4204 - you will see this because your request includes a postprocessor, and at present postprocessed images are not stored in bitmap cache, so the postprocess step has to take place again which causes a flash.

@lushan1314 - please can you answer @tyronen's latest question so that we can try to help you?

IanChilds avatar May 12 '15 08:05 IanChilds

@IanChilds Is there any future plan for postprocessed images to be stored?

raylee4204 avatar May 12 '15 14:05 raylee4204

It's #14 - but I don't know when/if it will get done unfortunately.

IanChilds avatar May 12 '15 14:05 IanChilds

sorry, i was busy.I just saw your reply.

@tyronen the image is jpeg. my code is simple , in the ListAdapter.getView

   if (StringUtils.isEmpty(user.iconUrl)) {
                    viewHolder.icon.setImageURI(FrescoUtils.getResUri(R.drawable.head_72));
                } else {
                    viewHolder.icon.setImageURI(FrescoUtils.getUri(user.iconUrl));
                }

in my case :
when the user clicks a button in the listview item, this line is selected,the state needs to be changed. So I changed the list item associated the state of an object , and then call the notifyDataSetChanged(),then this problem happend.

I want to have a possibility: maybe the bitmap cache was deleted. call notifyDataSetChanged() make it reload.

But i did not understand about : the bitmap cache should not be deleted when the image is showing.

finally , i found one way solve it :

That is to find out the current display item view, and then change their status, avoid call setImageURI method again, because the notifyDataSetChanged () - > getView () - > setImageURI () something like this:

int first = mListView.getFirstVisiblePosition();
int last = mListView.getLastVisiblePosition();
View convertView;
for (int i = 0; i <= last-first; i++) {
    convertView = mListView.getChildAt(i);
    if (convertView != null) {
        //to do someting about ui change....
    }
}

lushan1314 avatar May 13 '15 09:05 lushan1314

@tyronen this image is not animated

lushan1314 avatar May 13 '15 10:05 lushan1314

Can you give a uri for the image that failed please?

IanChilds avatar May 13 '15 10:05 IanChilds

you mean fresco:failureImage?

lushan1314 avatar May 14 '15 06:05 lushan1314

@tyronen i just tested ,GIF are happening every time, JPEG happens by chance.

lushan1314 avatar May 14 '15 06:05 lushan1314

@IanChilds in version 0.4.0, if image's format isn't a GIF, I can't find this problem.

but if the image is a GIF, it's still happened. you can use a uri for gif image ,and show on a ListView . you will find it.
thank you.

lushan1314 avatar May 20 '15 06:05 lushan1314

As @IanChilds explained, the flash may happen if you are re-setting the image to the view and the image is not found in the bitmap cache. Postprocessed images are not stored in the bitmap cache, but we are working on supporting this as we speak. Animated images are also not stored in the bitmap cache and therefore they are susceptible to this issue. Up until recently, Fresco didn't distinguish between animated and static GIFs so the issue used to affect the static GIFs as well. This has been fixed and static GIFs should no longer be affected by this issue. That being said, with the current version of Fresco, you should only experience this issue with animated and postprocessed images.

plamenko avatar Jul 08 '15 14:07 plamenko

ok , version 0.5.3?

lushan1314 avatar Jul 11 '15 02:07 lushan1314

This may have been fixed now.

plamenko avatar Dec 11 '15 14:12 plamenko

楼主现在解决了吗? 我现在还有这种问题。 在5.0或者5.0.2系统上,如果MemoryCacheParams中的maxCacheSize,也就是bitmap缓存大小设置的比较小的话,一旦调用notifyDataSetChanged,listview里面的图片就会闪。 但是同样的bitmap缓存大小设置下,在5.1.1系统上就不会出现这样的问题,猜测跟5.0系统的内存泄露有一些关系,但是fresco设置也有关系,因为只要把bitmap缓存设置大一些就不会闪烁了。 不过5.0系统bitmap缓存设置大一些又容易OOM

tianlang avatar Dec 15 '15 09:12 tianlang

闪烁的问题,我目前测试只有gif才会有。因为gif一般是不缓存的好像。你说的问题我没遇到,看上去是一样的,如果缓存很快就满了,很容易发生这种情况。还有一种办法有点恶心了,就是你不要调用notify,可以获取listview的可见区域做修改,并尽量不修改图片。不过不知道是否适合你的情况。缓存策略的话只能自己取舍了

lushan1314 avatar Dec 21 '15 17:12 lushan1314