问题
I'm trying to find out end of gif with glide.
this is the code that I find on web:
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);
the problem is , it doesn't accept GifDrawable in Target.
the error saying that:
回答1:
Use
target: com.bumptech.glide.request.target.Target<GifDrawable>?
instead of
Target<GifDrawable>
Try this
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)
回答2:
In your build.gradle file add following
Including Glide’s annotation processor requires dependencies on Glide’s annotations and the annotation processor:
compile 'com.github.bumptech.glide:annotations:4.8.0'
Add a dependency on Glide’s annotation processor:
repositories {
mavenCentral()
}
dependencies {
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
}
回答3:
Import the latest Glide
dependencies to grade file.
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
Then use one of these solutions:
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)
or
Glide.with(thisActivity)
.load(R.raw.logo_gif_motion_low)
.listener(object : RequestListener<Drawable> {
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
val gifDrawable = resource as GifDrawable?
gifDrawable?.let {
// TODO: Process your gif drawable here
}
return false
}
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
return false
}
})
.into(splashscreen)
来源:https://stackoverflow.com/questions/52291674/glide-does-not-accepting-gifdrawable-as-target-parameter