美文网首页
Glide 加载webp添加监听

Glide 加载webp添加监听

作者: 河马过河 | 来源:发表于2024-01-09 11:31 被阅读0次
  Glide.with(this)
                .load(R.drawable.ic_splash_icon_anim)
                .addListener(object : RequestListener<Drawable> {
                    override fun onLoadFailed(
                        e: GlideException?,
                        model: Any?,
                        target: Target<Drawable>?,
                        isFirstResource: Boolean
                    ): Boolean {
                        return false
                    }

                    override fun onResourceReady(
                        resource: Drawable?,
                        model: Any?,
                        target: Target<Drawable>?,
                        dataSource: DataSource?,
                        isFirstResource: Boolean
                    ): Boolean {
                        if (resource is WebpDrawable) {
                            resource.loopCount = 1
                            resource.registerAnimationCallback(object :
                                Animatable2Compat.AnimationCallback() {
                                override fun onAnimationEnd(drawable: Drawable?) {
                                    resource.unregisterAnimationCallback(this)
                                }
                            })
                        }
                        return false
                    }
                })
                .into(it.ivImage)

相关文章

网友评论

      本文标题:Glide 加载webp添加监听

      本文链接:https://www.haomeiwen.com/subject/eutandtx.html