代码之家  ›  专栏  ›  技术社区  ›  Yogesh Choudhary Paliyal

滑动加载图像不正确

  •  1
  • Yogesh Choudhary Paliyal  · 技术社区  · 7 年前

    enter image description here

    这里的图像没有完全加载。我不知道为什么。不知何故半占位符&不知何故半图像。有时它加载没有任何问题。

    我在用

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

    这是我的密码

    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" />
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   Zoe - Save the data dump 张群峰    6 年前

    在glide中有一个解决加载错误问题的方法

    进口 这个,还有 将sdk版本编译为27

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

    然后使用这个代码

    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);
    

    去除 这个来自 xml

     app:srcCompat="@mipmap/ic_launcher_round"
    
    推荐文章