Glide callback after success in Kotlin

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

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


        
5条回答
  •  囚心锁ツ
    2021-02-13 00:08

    If you only want to set the Bitmap into the ImageView using Glide then you can try out for a Extension Function in Kotlin with which you will only need to pass the parameters like uri/url or size.

    For Example:

    class KotlinActivity : AppCompatActivity() {
    
        var sampleImageView : ImageView? = null
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_kotlin)
            sampleImageView = findViewById(R.id.imageView) as ImageView?
            sampleImageView?.setImage("https://kbob.github.io/images/sample-3.jpg")
        }
    
    //Extension function for ImageView
        fun ImageView.setImage(url:String, context:Context){
            Glide.with(context).load(url).into(this)
        }
    }
    

提交回复
热议问题