Glide不接受GifDrawable作为目标参数

时间:2018-09-12 09:18:28

标签: android android-glide

我正试图找出gif的结尾。

这是我在网上找到的代码:

Glide.with(thisActivity).asGif().load(R.raw.logo_gif_motion_low).listener(object : RequestListener<GifDrawable> {
                override fun onLoadFailed(p0: GlideException?, p1: Any?, p2: Target<GifDrawable>, p3: Boolean): Boolean {

                }
                override  fun onResourceReady(p0: GifDrawable?, p1: Any?, p2: Target<GifDrawable>, p3: DataSource?, p4: Boolean): Boolean {

                    return false
                }
            }).into(splashscreen);

问题是,它在 Target 中不接受 GifDrawable

错误提示:

enter image description here

3 个答案:

答案 0 :(得分:3)

使用

target: com.bumptech.glide.request.target.Target<GifDrawable>?

代替

Target<GifDrawable>

尝试一下

    Glide.with(this).asGif().load("").listener(object : RequestListener<GifDrawable> {
        override fun onResourceReady(resource: GifDrawable?, model: Any?, target: Target<GifDrawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
            TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
        }

        override fun onLoadFailed(e: GlideException?, model: Any?, target: com.bumptech.glide.request.target.Target<GifDrawable>?, isFirstResource: Boolean): Boolean {
            TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
        }


    }).into(splashscreen)

答案 1 :(得分:1)

在您的build.gradle文件中添加以下内容

包括Glide的注释处理器需要依赖于Glide的注释和注释处理器:

compile 'com.github.bumptech.glide:annotations:4.8.0'

添加对Glide注释处理器的依赖性:

repositories {
 mavenCentral()
 }

dependencies {
 annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
}

答案 2 :(得分:1)

将最新的val someNumbers = arrayListOf(1, 5, 2) someNumbers.sortWith(Comparator { x, y -> 1 }) 依赖项导入成绩文件。

Glide

然后使用以下解决方案之一:

implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

Glide.with(thisActivity)
        .asGif()
        .load(R.raw.logo_gif_motion_low)
        .listener(object : RequestListener<GifDrawable> {
            override fun onResourceReady(resource: GifDrawable?, model: Any?, target: Target<GifDrawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
                // TODO: Process your gif drawable here
                return false
            }

            override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<GifDrawable>?, isFirstResource: Boolean): Boolean {
                return false
            }
        }).into(splashscreen)