通用图像加载器gridview在notifyDataSetChanged调用后闪烁

Lin*_*ton 8 android gridview adapter universal-image-loader

我正在使用UIL与此配置从FILE加载图像:

BitmapDisplayer displayer = new FadeInBitmapDisplayer(500) {

        @Override
        public Bitmap display(Bitmap bitmap, ImageView imageView,
                LoadedFrom loadedFrom) {
            if (loadedFrom != LoadedFrom.MEMORY_CACHE) {
                return super.display(bitmap, imageView, loadedFrom);
            } else {
                imageView.setImageBitmap(bitmap);
                return bitmap;
            }
        }

    };
    DisplayImageOptions options = new DisplayImageOptions.Builder()
            .cacheInMemory(true).resetViewBeforeLoading(true)
            .showImageForEmptyUri(R.drawable.thumbnail_no_image)
            .showImageOnFail(R.drawable.thumbnail_no_image)
            .displayer(displayer).build();
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
            context).defaultDisplayImageOptions(options)
            .memoryCacheSize(2 * 1024 * 1024).build();
    sLoader.init(config);
Run Code Online (Sandbox Code Playgroud)

GridView在我考虑选择任何项目后,我需要实现选择,我打电话notifyDataSetChanged让我的selectionOverlay可见.在此调用之后,所有图像开始重新加载,这导致GridView闪烁.我怎么能避免这个?

小智 0

也许这对您的要求有用。 https://github.com/koush/UrlImageViewHelper

使用以下代码显示来自 url 的图像。

UrlImageViewHelper.setUrlDrawable(holder.imageView2, url,
                    R.drawable.default, new UrlImageViewCallback() {
                        @Override
                        public void onLoaded(ImageView imageView,
                                Bitmap b, String url,
                                boolean loadedFromCache) {
                            // only show the animation
                            // if it was loaded from
                            // network or disk...
                            if (!loadedFromCache) {


                                if (b != null)
                                    holder.imageView2.setImageBitmap(b);

                                // ScaleAnimation scale = new ScaleAnimation(0,
                                // 1,
                                // 0, 1, ScaleAnimation.RELATIVE_TO_SELF,
                                // .5f, ScaleAnimation.RELATIVE_TO_SELF,
                                // .5f);
                                // scale.setDuration(1000);
                                // imageView.startAnimation(scale);
                            } else {

                                if (b != null)
                                    holder.imageView2.setImageBitmap(b);
                            }
                        }
                    });
Run Code Online (Sandbox Code Playgroud)