Android - ImageView: setImageBitmap VS setImageDrawable

前端 未结 5 620
灰色年华
灰色年华 2020-12-02 20:29

What is the difference between setImageBitmap and setImageDrawable?

I have an image which I would like to set dynamically from file. The tu

5条回答
  •  再見小時候
    2020-12-02 20:41

    Actually, you may see the difference, if you sometimes use null as an argument:

    imageView.setImageDrawable(null);
    Drawable d = imageView.getDrawable(); // d == null
    
    imageView.setImageBitmap(null);
    Drawable d = imageView.getDrawable(); // d == some BitmapDrawable, != null
    

    so if you are checking for existence of a drawable in ImageView, beware of it.

提交回复
热议问题