简体   繁体   中英

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

<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

import this, and keep the compile sdk version to 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

 app:srcCompat="@mipmap/ic_launcher_round"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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