作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Glide 将图像加载到我的 imageView(位于 recyclerview 中):
Glide.with(image.context).load(url)
.error(context.getDrawable(R.drawable.placeholder))
.into(image)
我看到 Glide 库还有一个“占位符”功能,它可以加载一个 Drawable,以便在图像仍在加载时显示。
最佳答案
感谢 Mike 在上面的评论:
有一个 ShimmerDrawable 类,您可以在其中构建一个微光 View 作为可在 Glide 中使用的 drawbale:
private val shimmer = Shimmer.AlphaHighlightBuilder()// The attributes for a ShimmerDrawable is set by this builder
.setDuration(1800) // how long the shimmering animation takes to do one full sweep
.setBaseAlpha(0.7f) //the alpha of the underlying children
.setHighlightAlpha(0.6f) // the shimmer alpha amount
.setDirection(Shimmer.Direction.LEFT_TO_RIGHT)
.setAutoStart(true)
.build()
// This is the placeholder for the imageView
val shimmerDrawable = ShimmerDrawable().apply {
setShimmer(shimmer)
}
Glide.with(image.context).load(url)
.placeholder(shimmerDrawable)
.error(context.getDrawable(R.drawable.placeholder))
.into(image)
关于android - 如何使用 View (微光)作为 ImageView 的占位符( Glide ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61076174/
我正在使用 Glide 将图像加载到我的 imageView(位于 recyclerview 中): Glide.with(image.context).load(url) .erro
我是一名优秀的程序员,十分优秀!