实现方式一:Glide
glide加载圆角和centercrop的问题,采用如下方式,设置两个Transformer
class RoundedCornerCenterCrop(val radius: Int = 0) : BitmapTransformation() {
override fun updateDiskCacheKey(messageDigest: MessageDigest) {
}
override fun transform(pool: BitmapPool, toTransform: Bitmap, outWidth: Int, outHeight: Int): Bitmap {
val bitmap = TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight)
return TransformationUtils.roundedCorners(pool, bitmap, radius)
}
}
实现方式二
ViewOutlineProvider
view.outlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
val radius = 8.dp.toFloat()
outline.setRoundRect(0, 0, view.width, view.height, radius)
}
}
v.clipToOutline = true
网友评论