通过Glide播放/停止gif

5,054 阅读1分钟

添加依赖

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()
        }## 添加依赖

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](https://gitee.com/cxyzy1/stop_gif)

    }
}