通过Glide播放/停止gif

添加依赖

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/cxyzy1/stop_gif

发布了407 篇原创文章 · 获赞 90 · 访问量 39万+

猜你喜欢

转载自blog.csdn.net/yinxing2008/article/details/103504541