
将Drawable的长宽比例 同步 到ImageView组件上

Glide.with(this)
.load(url)
.onlyRetrieveFromCache(true)
.error(R.drawable.icon_splash_bg_new)
.into(object : CustomTarget<Drawable>() {
override fun onResourceReady(
resource: Drawable,
transition: Transition<in Drawable>?
) {
if (resource.intrinsicWidth>0) {
splashImage?.post {
val radio =
resource.intrinsicWidth.toFloat() / resource.intrinsicHeight.toFloat()
splashImage.layoutParams.height =
(splashImage.width.toFloat() / radio).toInt()
Glide.with(this@SplashActivity).load(resource).into(splashImage)
}
} else {
splashImage?.let {
Glide.with(this@SplashActivity).load(resource).into(it)
}
}
}
override fun onLoadCleared(placeholder: Drawable?) {
}
})