代码之家  ›  专栏  ›  技术社区  ›  Ahad Porkar

Glide不接受giftrawable作为目标参数

  •  2
  • Ahad Porkar  · 技术社区  · 7 年前

    我想用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);
    

    问题是,它不接受 天才的 在里面 目标 .

    错误是说:

    enter image description here

    3 回复  |  直到 7 年前
        1
  •  6
  •   AskNilesh    7 年前

    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)
    
        2
  •  1
  •   Sasi Kumar    7 年前

    包含Glides批注处理器需要依赖于Glides批注和批注处理器:

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

    添加对Glides批注处理器的依赖关系:

    repositories {
     mavenCentral()
     }
    
    dependencies {
     annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
    }
    
        3
  •  1
  •   Son Truong    7 年前

    导入最新版本 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)
    

    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)