1. Glide loads circular avatar
Effect
R.mipmap.head_icon is the default round avatar
ImageView mImage = findViewById(R.id.image);
RequestOptions options = new RequestOptions()
.placeholder(R.mipmap.head_icon)
.circleCropTransform();
Glide.with(this)
.load("图像Uri")
.apply(options)
.into(mImage);
2. Glide sets rounded corners to the image
Example: Set the image rounded corners to 10dp
Effect
RequestOptions options = new RequestOptions()
.placeholder(R.drawable.capture_default)
.bitmapTransform(new RoundedCorners(dip2px(mContext, 10)));
Glide.with(this)
.load("图像Uri")
.apply(options)
.into(mImage);
Unit conversion method
public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}