简体   繁体   English

滑动不正确加载图像

[英]Glide not loading image properly

在此输入图像描述

Here the image is not completely loaded. 这里的图像没有完全加载。 I don't know why. 我不知道为什么。 Somehow half placeholder & somehow half image. 不知何故半占位符和不知何故的半图像。 Sometimes it loads without any issue. 有时它加载没有任何问题。

I am using 我在用

implementation 'com.github.bumptech.glide:glide:3.7.0'

Here is my code 这是我的代码

val headerView = nav_view.getHeaderView(0)
Glide.with(act).load(userdata.image).placeholder(R.drawable.ic_male).thumbnail(0.2f).into(headerView.imgNavDp)

XML XML

<de.hdodenhof.circleimageview.CircleImageView
            android:layout_marginLeft="@dimen/dim_5"
            android:id="@+id/imgNavDp"
            android:layout_width="@dimen/dim_76"
            android:layout_height="@dimen/dim_76"
            android:elevation="@dimen/dim_10"
            android:layout_gravity="center_vertical"
            app:srcCompat="@mipmap/ic_launcher_round" />

There is a work around to handle loading error issues in Glide 有一种解决方法可以处理Glide中的加载错误问题

import this, and keep the compile sdk version to 27 导入它,并将compile sdk版本保持为27

compile 'com.github.bumptech.glide:glide:3.8.0'

then Use this code 然后使用此代码

Glide.with(context)
        .load(userdata.image)
        .placeholder(R.drawable.ic_male)
        .error(R.drawable.imagenotfound)
        .listener(new RequestListener<String, GlideDrawable>() {
            @Override
            public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                // log exception
                Log.e("TAG", handle error case", e);
                return false; 
            }

            @Override
            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                 Log.e("TAG", handle success case here", e);
                return false;
            }
        })
        .into(headerView.imgNavDp);

and remove this from xml 并从xml 删除

 app:srcCompat="@mipmap/ic_launcher_round"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM