| | |
| | | import android.content.Context; |
| | | import android.widget.ImageView; |
| | | |
| | | import androidx.annotation.IdRes; |
| | | import androidx.annotation.NonNull; |
| | | |
| | | import com.bumptech.glide.Glide; |
| | | import com.bumptech.glide.load.resource.bitmap.CenterCrop; |
| | | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
| | |
| | | Glide.with(context).resumeRequests(); |
| | | } |
| | | |
| | | /** |
| | | * 加载图片 |
| | | * |
| | | * @param imageView 图片控件 |
| | | * @param url 链接 |
| | | * @param error 加载异常占位图资源id |
| | | * @param placeHolder 占位图资源id |
| | | * @param radius 圆角 单位dp |
| | | */ |
| | | public void load(@NonNull ImageView imageView, |
| | | String url, |
| | | @IdRes int error, @IdRes int placeHolder, |
| | | float radius) { |
| | | float value = radius * imageView.getContext().getResources().getDisplayMetrics().density; |
| | | Glide.with(imageView) |
| | | .load(url) |
| | | .transform(new CenterCrop(), new RoundedCorners((int) value)) |
| | | .placeholder(placeHolder) |
| | | .error(error) |
| | | .into(imageView); |
| | | } |
| | | |
| | | private GlideEngine() { |
| | | } |
| | | |