加载gif,AnimatedImageDrawable 最简单的用法

主要通途 加载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()
            }
        }
    }

你可能感兴趣的:(加载gif,AnimatedImageDrawable 最简单的用法)