Android Glide加载圆角图片及圆形图片
2019-10-23 本文已影响0人
带带我
加载圆角图片
public static void displayRoundrect(Context context, ImageView imageView, String url, int corner) throws IllegalArgumentException{
//加载圆角矩形 corner 圆角度数
if (imageView == null) {
throw new IllegalArgumentException("argument error");
}
//如果加载其他形状的可以设置不同的 GlideRoundedCorners.CornerType
//如 GlideRoundedCorners.CornerType.TOP,GlideRoundedCorners.CornerType.TOP_LEFT_BOTTOM_RIGHT 等等
GlideRoundedCorners c = new GlideRoundedCorners(corner, GlideRoundedCorners.CornerType.ALL);
RequestOptions options = new RequestOptions().optionalTransform(c);
Glide.with(context)
.load(url)
.apply(options)
.into(imageView);
}
加载圆形图片
public static void displayCircle(Context context, ImageView imageView, String url) throws IllegalArgumentException{
//加载圆形图片
if (imageView == null) {
throw new IllegalArgumentException("argument error");
}
RequestOptions options = new RequestOptions()
//圆形
.circleCrop()
//占位图
.placeholder(R.drawable.user_default_head)
//加载失败图
.error(R.drawable.user_default_head);
Glide.with(context)
.load(url)
.apply(options)
.into(imageView);
}