滑行需要太多时间来加载,有时却无法加载图像

时间:2019-11-07 18:45:22

标签: android android-glide

我正在通过Glide从服务器加载多个图像。我使用ViewPager显示此图像。但是有时候,当我快速滚动时,它不会加载任何图像并崩溃。我使用PhotoView代替ImageView(用于缩放)。那么如何防止此错误?

        Glide.with(context).load(ApiClient.Base_URL + list.get(position).getImage())
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .dontAnimate()
                .fitCenter()
                .error(R.drawable.errorcircle128white)
                .listener(new RequestListener<Drawable>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                        lessonglideprogress.setVisibility(View.GONE);
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                        lessonglideprogress.setVisibility(View.GONE);
                        return false;
                    }
                })
                .into(photoView);

    PhotoViewAttacher pAttacher;
    pAttacher = new PhotoViewAttacher(photoView);
    pAttacher.update();

    container.addView(view);
    return view;
}

日志:

W/Glide: Load failed for url.jpg with size [1080x1386]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There were 6 causes:
java.lang.OutOfMemoryError(Failed to allocate a 3725580 byte allocation with 3006928 free bytes and 2MB until OOM)
java.lang.OutOfMemoryError(Failed to allocate a 3725580 byte allocation with 3005408 free bytes and 2MB until OOM)
java.lang.OutOfMemoryError(Failed to allocate a 3725580 byte allocation with 2922632 free bytes and 2MB until OOM)
java.lang.OutOfMemoryError(Failed to allocate a 3725580 byte allocation with 2920952 free bytes and 2MB until OOM)
java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0x80000000)
java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0x80000000)
 call GlideException#logRootCauses(String) for more detail
  Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{DirectByteBuffer->Object->Drawable}, REMOTE
There were 2 causes:
java.lang.OutOfMemoryError(Failed to allocate a 3725580 byte allocation with 3006928 free bytes and 2MB until OOM)
java.lang.OutOfMemoryError(Failed to allocate a 3725580 byte allocation with 3005408 free bytes and 2MB until OOM)
 call GlideException#logRootCauses(String) for more detail
    Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->GifDrawable->Drawable}
    Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->Bitmap->Drawable}
There was 1 cause:
java.lang.OutOfMemoryError(Failed to allocate a 3725580 byte allocation with 3006928 free bytes and 2MB until OOM)
 call GlideException#logRootCauses(String) for more detail
      Cause (1 of 1): class java.lang.OutOfMemoryError: Failed to allocate a 3725580 byte allocation with 3006928 free bytes and 2MB until OOM
    Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{DirectByteBuffer->BitmapDrawable->Drawable}
There was 1 cause:
java.lang.OutOfMemoryError(Failed to allocate a 3725580 byte allocation with 3005408 free bytes and 2MB until OOM)
 call GlideException#logRootCauses(String) for more detail
      Cause (1 of 1): class java.lang.OutOfMemoryError: Failed to allocate a 3725580 byte allocation with 3005408 free bytes and 2MB until OOM

0 个答案:

没有答案