添加依赖
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
播放gif
Glide.with(this).asGif().load(R.drawable.test).into(imageView)
停止gif
button.setOnClickListener {
if (imageView.drawable is GifDrawable) {
val drawable = imageView.drawable as GifDrawable
if (drawable.isRunning) {
drawable.stop()
} else {
drawable.start()
}
}
}
源代码
https://gitee.com/hspbc/stop_gif