-
Notifications
You must be signed in to change notification settings - Fork 14
图片加载
William edited this page Sep 11, 2024
·
3 revisions
- 图片加载(使用的Glide)
- 所有的圆角角度会同步作用到失败与占位图上面
/**
* 加载图片
* @param any 图片资源Glide所支持的
* @param roundingRadius 图片圆角角度
* @param errorResId 加载错误占位图
*/
fun ImageView.vbLoad(
any: Any,
roundingRadius: Int = 0,
errorResId: Int = R.mipmap.vb_iv_empty,
)
/**
* 加载不同圆角图片
* @param any 图片资源Glide所支持的
* @param topLeft 顶部左边圆角
* @param topRight 顶部右边圆角
* @param bottomLeft 底部左边圆角
* @param bottomRight 底部右边圆角
* @param errorResId 加载错误占位图
*/
fun ImageView.vbLoadRounded(
any: Any,
topLeft: Int = 0,
topRight: Int = 0,
bottomLeft: Int = 0,
bottomRight: Int = 0,
errorResId: Int = R.mipmap.vb_iv_empty,
)
/**
* 加载圆形图片
* @param any 图片资源Glide所支持的
* @param errorResId 加载错误占位图
*/
fun ImageView.vbLoadCircle(any: Any, errorResId: Int = R.mipmap.vb_iv_empty)
/**
* 加载图片监听
* @param any 图片资源Glide所支持的
* @param w 图片设置宽度
* @param h 图片设置高度
* @param success 图片加载成功
* @param error 图片加载失败
*/
fun Context.vbLoadListener(
any: Any?,
w: Int = 0,
h: Int = 0,
success: ((Drawable) -> Unit),
error: (() -> Unit)? = null,
)
- 代码使用
imageView.vbLoadCircle(file)
imageView.vbLoad(file, 10)
imageView.vbLoadRounded(file, 10,10,10,10)
- xml里面使用
<ImageView
android:layout_width="match_parent"
android:scaleType="centerCrop"
app:vb_img_url="@{bean.url}"
app:vb_img_radius="@{10f}"
app:vb_circle="@{true}"
android:layout_height="match_parent" />