-
Notifications
You must be signed in to change notification settings - Fork 6.2k
同时使用placeholder、thumbnail时高清图显示错误 #5666
Copy link
Copy link
Open
Description
我封装了一个加载图片的公共方法,下面是源码:
fun fLoad(
view: ImageView,
url: String?,
thumbnailUrl: String? = null,
overrideWH: (IntArray)? = null,
onResourceReady: ((Drawable) -> Unit)? = null,
onLoadFailed: ((GlideException?) -> Unit)? = null,
width: Boolean = false
) {
val context = view.context
if (!checkGlideContext(context)) {
return
}
val toImageUrl = url.toImageUrl(width = width)
val toThumbnailUrl = thumbnailUrl?.toImageUrl(width = width)
val requestListener = object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>,
isFirstResource: Boolean
): Boolean {
if (!checkGlideContext(context)) return false
onLoadFailed?.invoke(e)
return false
}
override fun onResourceReady(
resource: Drawable,
model: Any,
target: Target<Drawable>?,
dataSource: DataSource,
isFirstResource: Boolean
): Boolean {
if (!checkGlideContext(context)) return false
onResourceReady?.invoke(resource)
return false
}
}
var builder = Glide.with(view.context)
.load(toImageUrl)
.listener(requestListener)
if (!toThumbnailUrl.isNullOrEmpty()) {
val thumbBuilder = Glide.with(view.context)
.asDrawable()
.load(toThumbnailUrl)
.listener(requestListener)
builder = builder.thumbnail(thumbBuilder)
}
if (overrideWH != null && overrideWH.isNotEmpty()) {
builder = builder.override(
overrideWH[0],
if (overrideWH.size > 1) overrideWH[1] else overrideWH[0]
)
}
builder.placeholder(R.color.color_1b1b1b)
.error(R.color.color_1b1b1b)
.into(view)
}我使用下面的代码进行调用,加载两张网络图片,发现缩略图显示正常但高清图加载成功后显示失常。我排查了一段时间,发现当我删除placeholder设置后高清图就正常了,或者使用submit()而非into(view)也行。下面是调用的代码:
fLoad(binding.thumb, mainUrl, coverUrl, onResourceReady = { drawable ->
val ratio = drawable.intrinsicWidth.toFloat() / drawable.intrinsicHeight.toFloat()
var thumbWidth = binding.thumb.width
val thumbHeight =
min((thumbWidth / ratio).toInt(), binding.layoutParent.height)
thumbWidth = (thumbHeight * ratio).toInt()
binding.thumb.updateLayoutParams {
width = thumbWidth
height = thumbHeight
}
binding.skeletonView.isVisible = false
binding.groupWatermark.isVisible = showWatermark
binding.layoutMakeVideo.isVisible = false
})请问这是何原因?请大佬帮忙排查。
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels