android Glide 如何设置成圆角
时间: 2024-03-10 13:50:42 浏览: 20
使用 Glide 将图片设置成圆角需要使用 `Transformations` 类中的 `RoundedCorners` 方法,具体步骤如下:
1. 在 app 模块的 build.gradle 文件中添加以下依赖:
```
dependencies {
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}
```
2. 在代码中使用 `Transformations` 类中的 `RoundedCorners` 方法对图片进行圆角处理:
```
Glide.with(this)
.load(imageUrl)
.transform(new RoundedCorners(radius))
.into(imageView);
```
其中,`imageUrl` 为图片的 URL,`radius` 为圆角的半径,单位为像素。
3. 如果需要同时对图片进行圆形处理和圆角处理,可以先使用 `CircleCrop` 方法将图片剪裁为圆形,然后再使用 `RoundedCorners` 方法对图片进行圆角处理:
```
Glide.with(this)
.load(imageUrl)
.transform(new CircleCrop(), new RoundedCorners(radius))
.into(imageView);
```
4. 如果需要在圆角处理的同时设置边框,可以使用 `MultiTransformation` 类将 `RoundedCorners` 和 `BorderTransform` 组合起来使用:
```
Glide.with(this)
.load(imageUrl)
.transform(new MultiTransformation<>(new RoundedCorners(radius), new BorderTransform(borderWidth, borderColor)))
.into(imageView);
```
其中,`borderWidth` 和 `borderColor` 分别为边框的宽度和颜色。
以上是使用 Glide 将图片设置成圆角的方法,具体使用可以参考 Glide 的官方文档。