How to avoid flickering while updating gridview?

前端 未结 9 2195
谎友^
谎友^ 2021-01-05 07:01

I have a gridview. Im displaying images from the array of 10 images. After 1 minute i\'m adding 5 more images. To update the gridview i\'m using the following code.

<
9条回答
  •  别那么骄傲
    2021-01-05 07:56

    The solution is to not reload your image when it did not change.

    In your adapters getView() do:

    // schedule rendering:
    final String path = ... (get path here);
    if (holder.lastImageUrl == null || !holder.lastImageUrl.equals(path)
                    || holder.headerImageView.getDrawable() == null) {
        // refresh image
        imageLoader.displayImage(imageUri, imageAware);
    } else {
        // do nothing, image did not change and does not need to be updated
    }
    

    on success (add a ImageLoadingListener) you set holder.lastImageUrl = path, on fail and cancel you set holder.lastImageUrl to null so that it will reload next time.

提交回复
热议问题