主要通途 加载gif资源
代码
@Throws(IOException::class)
private fun decodeImage() {
val decodedAnimation = ImageDecoder.decodeDrawable(
ImageDecoder.createSource(resources, R.mipmap.gif1))
iv_first.setImageDrawable(decodedAnimation)
btn_start.setOnClickListener {
if (decodedAnimation is AnimatedImageDrawable) {
// Prior to start(), the first frame is displayed.
/*设置重复次数*/
decodedAnimation.repeatCount = 0
(decodedAnimation as AnimatedImageDrawable).start()
}
}
btn_stop.setOnClickListener {
if (decodedAnimation is AnimatedImageDrawable) {
// Prior to start(), the first frame is displayed.
(decodedAnimation as AnimatedImageDrawable).stop()
}
}
}