Glide: The image is loaded for the first time and can not be displayed. Glide4.2.0

Created on 14 Oct 2017  路  9Comments  路  Source: bumptech/glide

The image is loaded for the first time and can not be displayed.

The second load, display normal

Using imageView, glide 4.2.0

code is

protected void drawMarker(List<DeviceInfo> deviceInfos) {
        if (null == deviceInfos || deviceInfos.size() <= 0) {
            return;
        }
       //--------------The code here is normal--------
        RequestOptions options = new RequestOptions()
                .circleCrop()
                .placeholder(R.mipmap.default_user_header)
                .error(R.mipmap.default_user_header)
                .priority(Priority.HIGH);

        Glide.with(context)
                .load("http://img.duoziwang.com/2016/09/15/16582141.jpg")
                .apply(options)
                .into(mDrawerImage);
      //--------The code here is normal-----------
        int count = deviceInfos.size();
        for (int i = 0; i < count; i++) {
            if (null != locationLatLng) {

                DeviceAddressIconView iconView = new DeviceAddressIconView(AMapMainActivity.this);
                 //--------------The code here is not normal
                iconView.setIcon(context, deviceInfos.get(i).getHeadImage(), R.drawable.device_icon);
                 //--------------The code here is not normal
                    Gps gps = PositionUtil.GPS84_To_GCJ02(Double.valueOf(deviceInfos.get(i).getLat()), Double.valueOf(deviceInfos.get(i).getLongitude()));
                    markerList.add(MapUtil.addMarker(aMap, gps.getWgLat(), gps.getWgLon(), iconView));

            }
        }
    }

DeviceAddressIconView code is

public class DeviceAddressIconView extends RelativeLayout {

    private ImageView deviceIsLock;
    private ImageView deviceAddressIcon;
    private ImageView deviceLocationBg;

    public DeviceAddressIconView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    public DeviceAddressIconView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public DeviceAddressIconView(Context context){
        super(context);
        initView(context);
    }

    public void initView(Context mContext){
        View view = LayoutInflater.from(mContext).inflate(R.layout.view_device_address_icon,this,true);
        deviceIsLock = (ImageView) view.findViewById(R.id.device_address_is_lock);
        deviceAddressIcon = (ImageView) view.findViewById(R.id.device_address_icon);
        deviceLocationBg = (ImageView) view.findViewById(R.id.home_location_bg);
    }

    /**
     * 璁剧疆鍥剧墖
     * @param url 璺緞
     */
    public void setIcon(Context context,String url,int resId) {

        Glide.with(context)
                .load(url)
                .into(deviceAddressIcon);
    }
}

R.layout.view_device_address_icon code is

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

  <ImageView
      android:id="@+id/home_location_bg"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@mipmap/home_location_icon"
      android:layout_centerInParent="true" />

   <ImageView
       android:id="@+id/device_address_icon"
       android:layout_width="@dimen/device_address_icon_width"
       android:layout_height="@dimen/device_address_icon_width"
       android:layout_centerInParent="true"
       android:src="@drawable/device_icon" />

    <ImageView
        android:id="@+id/device_address_is_lock"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/home_icon_protect"
        android:layout_toRightOf="@+id/device_address_icon"
        android:layout_marginTop="@dimen/btn_selector_radius"
        android:visibility="invisible"/>
</RelativeLayout>

Tried a lot of ways, do not know where the problem is, please help me,thank you very much

stale

Most helpful comment

Strange, I did some more investigating and it seems that this issue occurs only when I call:
transition(DrawableTransitionOptions.withCrossFade())
I also tried to to call it with
.circleCrop()
(as is OPs code) but the issue didn't occur then. Moreover, I am unable to reproduce it on glide v4.0.0 , only on 4.1.1 and 4.2.0

All 9 comments

What do you mean by can't be displayed?

The first paragraph of the code line 23, use setIcon() method , This setIcon() is in the second paragraph of the code. first time can not display the image, but The second load, display normal.

thank you for your reply

I found that the above code sometimes shows the correct picture, sometimes showing the placeholder.please help me.thank you very very much @sjudd

See http://bumptech.github.io/glide/doc/debugging.html. Do you see exceptions or load failures?

thank you for your reply.

I enable logging for adb shell setprop log.tag.Glide DEBUG and adb shell setprop log.tag.Glide VERBOSE

I load image ,other view show correct, that view show the placeholder. But I don't see any glide log unless W/Glide: Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored.

I am able to reproduce the same issue. After turning on logging it seems that it occurs only when image is loaded from DATA_DISK_CACHE.

Basically, first time I load the picture ImageView stays clear:

10-25 22:50:03.971 8261-8261/com.bimber.debug D/Glide: Finished loading BitmapDrawable from DATA_DISK_CACHE for https://firebasestorage.googleapis.com/v0/b/bimber-staging.appspot.com/o/photos%2Fprofiles%2FmA4dTVuQndV6l3lYUOFT5o5EMuT2%2F-KxFDp3SIVxOHtKFR3No?alt=media&token=94a46676-d325-4bb2-98c6-87e40183af64 with size [672x672] in 38.522452 ms

Next time I load this image it loads from MEMORY CACHE and displays on ImageView just fine:

10-25 22:50:43.614 8261-8261/com.bimber.debug D/Glide: Finished loading BitmapDrawable from MEMORY_CACHE for https://firebasestorage.googleapis.com/v0/b/bimber-staging.appspot.com/o/photos%2Fprofiles%2FmA4dTVuQndV6l3lYUOFT5o5EMuT2%2F-KxFDp3SIVxOHtKFR3No?alt=media&token=94a46676-d325-4bb2-98c6-87e40183af64 with size [672x672] in 0.523594 ms

Strange, I did some more investigating and it seems that this issue occurs only when I call:
transition(DrawableTransitionOptions.withCrossFade())
I also tried to to call it with
.circleCrop()
(as is OPs code) but the issue didn't occur then. Moreover, I am unable to reproduce it on glide v4.0.0 , only on 4.1.1 and 4.2.0

@Sroka what View are you using? Maybe CircularImageView or one of the others that don't handle animated Drawables?

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kenneth2008 picture kenneth2008  路  3Comments

kooeasy picture kooeasy  路  3Comments

StefMa picture StefMa  路  3Comments

Tryking picture Tryking  路  3Comments

piedpiperlol picture piedpiperlol  路  3Comments