Glide加载圆形图片,View是de.hdodenhof.circleimageview.CircleImageView
废话不多说,直接怼解决方案:
public static void loadCircleImage(Context context, final ImageView imageView, String url) {
RequestOptions options = new RequestOptions()
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.error(R.drawable.error)
.priority(Priority.HIGH);
RequestBuilder<Drawable> requestBuilder = Glide.with(context)
.load(url);
requestBuilder.apply(options)
.thumbnail(Glide.with(context).load(url))
// .transition(DrawableTransitionOptions.withCrossFade())
.into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
imageView.setImageDrawable(resource);
}
});
}
需要添加
.into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
imageView.setImageDrawable(resource);
}
}
本文提供了一种使用Glide库加载圆形图片到CircleImageView的方法,通过自定义SimpleTarget实现图片资源准备后的处理,适用于Android应用开发中需要圆形头像等场景。

1089

被折叠的 条评论
为什么被折叠?



