简介
当前版本4.8.0
实现方式:添加listener,回调方法onResourceReady
中得到GifDrawable
,然后设置播放次数
代码示例
Glide.with(this)
.load(R.drawable.three_time)
.listener(object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean = false
override fun onResourceReady(
resource: Drawable?,
model: Any?, target:
Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
if (resource is GifDrawable) {
resource.setLoopCount(GifDrawable.LOOP_INTRINSIC) //设置次数
}
return false
}
})
.into(imageView)
关键方法
GifDrawable.setLoopCount(int loopCount)
//传值
GifDrawable.LOOP_FOREVER //GIF图循环播放
GifDrawable.LOOP_INTRINSIC //GIF图的默认播放次数
GIF默认播放次数
GIF本身是可以设置播放次数的,可参考: 用PS修改GIF动图循环播放次数
平时打开GIF图默认是循环播放的,那是因为看图软件实现了循环播放的原因。可使用浏览器打开GIF图即可。
网友评论