Glide有时显示半图像

时间:2018-02-27 13:19:49

标签: android image android-glide

我在我的应用中使用滑行来显示图像。图像来自亚马逊s3并在图像视图中加载。但有时滑行只是加载一部分图像。我正在使用它的缓存策略。当我将缓存设置为false时,每次都会加载图像。这将花费大量数据给用户。所以我认为那不是一个好选择。下面是我的代码和问题图片。

enter image description here

滑翔代码:

Glide.with(context).load(posts.get(position).getFile()).placeholder(R.drawable.qurbani_background_6).error(R.drawable.error_image)
                    .fitCenter().listener(new RequestListener<File, GlideDrawable>() {
                @Override
                public boolean onException(Exception e, File model, Target<GlideDrawable> target, boolean isFirstResource) {
                    holder.progressBar.setVisibility(View.GONE);
                    //Toast.makeText(context , e.toString() , Toast.LENGTH_LONG).show();
                    //HomeActivity h = new HomeActivity();
                    //h.galleryTask();
                    return false;
                }

                @Override
                public boolean onResourceReady(GlideDrawable resource, File model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                    holder.progressBar.setVisibility(View.GONE);
                    return false;
                }
            }).into(holder.postImage);

和亚马逊s3下载听众代码:

public void transferObserverListener(final TransferObserver transferObserver)
    {
        transferObserver.setTransferListener(new TransferListener(){

            @Override
            public void onStateChanged(int id, TransferState state)
            {
                Log.e("statechange", state+"");
                if(state.toString() == "COMPLETED")
                {
                    adapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onProgressChanged(int id, long bytesCurrent, long bytesTotal)
            {
                int percentage = 0;
                if(bytesTotal != 0)
                {
                    percentage = (int) (bytesCurrent / bytesTotal * 100);
                }
                Log.e("percentage",percentage +"");
            }

            @Override
            public void onError(int id, Exception ex)
            {
                p.dismiss();
                Log.e("error",ex.toString());
            }

        });
    }

我正在使用回收站视图。图像应该在全视图中加载。请告诉我我做错了什么。

1 个答案:

答案 0 :(得分:1)

我使用了com.github.bumptech.glide:glide:4.3.1

try {
                        RequestOptions requestOption =
                                new RequestOptions().placeholder(R.drawable.box).
                                        error(R.drawable.box)
                                        .diskCacheStrategy(DiskCacheStrategy.ALL);


                            Glide.with(context).load(assetComponentModel.getUrl())
                                    .apply(requestOption)
                                    .transition(DrawableTransitionOptions.withCrossFade())
                                    .into(new SimpleTarget<Drawable>() {
                                        @Override
                                        public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
                                            mHolder.assets_image.setImageDrawable(resource);
                                        }

                                        @Override
                                        public void onLoadCleared(@Nullable Drawable placeholder) {
                                            mHolder.assets_image.setImageDrawable(placeholder);
                                        }

                                        @Override
                                        public void onLoadFailed(@Nullable Drawable errorDrawable) {
                                            mHolder.assets_image.setImageDrawable(errorDrawable);
                                        }

                                        @Override
                                        public void onLoadStarted(@Nullable Drawable placeholder) {
                                            mHolder.assets_image.setImageDrawable(placeholder);
                                        }
                                    });
                        } 

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

并使用rclOfferListView.setItemViewCacheSize(list.size());

在片段中使用了破坏代码

 @Override
public void onDestroy() {
    try {
        if (rclOfferListView != null)
            rclOfferListView.getRecycledViewPool().clear();
    } catch (Exception e) {
        e.getMessage();
    }
    super.onDestroy();
}

结果:图片只显示一次。没有任何半图像。