Glide 4.x Placeholder(佔位圖)不會被處理成圓角
阿新 • • 發佈:2018-12-21
解決這個問提一種方法就是讓UI直接切圓角圖;另一箇中就是通過thumbnail
方法對佔位圖再做圓角處理,具體實現如下:
public static void loadRoundImg(ImageView imageView, String url, @DrawableRes int placeholderId,
@DrawableRes int errorId, float radius) {
Glide.with(imageView.getContext()).load(url)
. apply(new RequestOptions().placeholder(placeholderId).error(errorId).centerCrop()
.transform(new GlideRoundTransform(imageView.getContext(), radius)))
.thumbnail(loadTransform(imageView.getContext(),placeholderId,radius))
.thumbnail(loadTransform (imageView.getContext(),errorId,radius))
.into(imageView);
}
private static RequestBuilder<Drawable> loadTransform(Context context, @DrawableRes int placeholderId, float radius) {
return Glide.with(context)
.load(placeholderId)
. apply(new RequestOptions().centerCrop()
.transform(new GlideRoundTransform(context, radius)));
}