Difference between Android ImageView SRC and background

When using glide before, I was confused by the image settings of ImageView (a very low-level problem, which is a common problem), so I went to take a look at ImageView to supplement the foundation.

First, ImageView has two properties for displaying images, SRC and background. From the name, we can know that the first is the resource (picture) and the second is the background (picture frame).

How do I set these two values?

Of the four methods that set background, setbackgrounddrawable() is the @ deprecated method, which is finally called.

Some differences:

1. SRC stores the size of the original drawing, and the background will be stretched according to the size of the component. 2. SRC is the content (picture) of the picture, and background is the background (picture frame) of the picture, which can exist at the same time. 3. Background can set transparency, SRC cannot. 4. Scaletype works only on SRC. This text explains very clearly - > scaletype detailed explanation 5 Setbackgrounddrawable is used when drawing in custom ImageView. If you use setimagedrawable, you need to set setinternalheight and setinternalwidth, otherwise they will not be displayed. See the source code for the specific reasons.

Through this article, I hope to help the little partners in need. Thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>