Glide callback after success in Kotlin

前端 未结 5 1768
孤独总比滥情好
孤独总比滥情好 2021-02-12 23:37
   private SimpleTarget target = new SimpleTarget() {  

    @Override
    public void onResourceReady(Bitmap bitmap, GlideAnimation glideAnimation) {
             


        
5条回答
  •  离开以前
    2021-02-13 00:11

     Glide.with(context)
            .load(url)
            .listener(object : RequestListener {
                override fun onLoadFailed(p0: GlideException?, p1: Any?, p2: Target?, p3: Boolean): Boolean {
                    TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
                }
                override fun onResourceReady(p0: Drawable?, p1: Any?, p2: Target?, p3: DataSource?, p4: Boolean): Boolean {
                    Log.d(TAG, "OnResourceReady")
                    //do something when picture already loaded
                    return false
                }
            })
            .into(imgView)
    

    With Glide you can add Listener to your chain, which monitor state of your image loading. You have to override two methods, in onResourceReady method you have callback that your image is already loaded and you can do something , for example hide loader or let finish animation from another view. In onLoadFailed you get information about some error while loading and also you can react somehow. This way you can avoid those errors.

提交回复
热议问题