簡介
當(dāng)前版本4.8.0
實(shí)現(xiàn)方式:添加listener,回調(diào)方法onResourceReady
中得到GifDrawable
苍柏,然后設(shè)置播放次數(shù)
代碼示例
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) //設(shè)置次數(shù)
}
return false
}
})
.into(imageView)
關(guān)鍵方法
GifDrawable.setLoopCount(int loopCount)
//傳值
GifDrawable.LOOP_FOREVER //GIF圖循環(huán)播放
GifDrawable.LOOP_INTRINSIC //GIF圖的默認(rèn)播放次數(shù)
GIF默認(rèn)播放次數(shù)
GIF本身是可以設(shè)置播放次數(shù)的,可參考: 用PS修改GIF動(dòng)圖循環(huán)播放次數(shù)
平時(shí)打開GIF圖默認(rèn)是循環(huán)播放的姜贡,那是因?yàn)榭磮D軟件實(shí)現(xiàn)了循環(huán)播放的原因试吁。可使用瀏覽器打開GIF圖即可楼咳。