Android Glide載入圖片設定監聽 kotlin
阿新 • • 發佈:2021-02-05
技術標籤:AndroidGlideKotlinandroid
Glide.with(this) .load(path) //path="地址" .apply(RequestOptions().diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true)) .addListener(object : RequestListener<Drawable?>{ override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable?>?, isFirstResource: Boolean): Boolean { //圖片載入失敗後返回 //e:報錯資訊 //model:load方法裡面的值 //target:ImageView本身 //isFirstResource:是否是第一個資源 return false } override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable?>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { //圖片載入成功後返回 //resource:目標圖bitmap //model:load方法裡面的值 //target:ImageView本身 //dataSource:圖片資源的來源,MEMORY_CACHE、LOCAL、REMOTE //isFirstResource:是否是第一個資源 return false } }) .into(iv_code)