Android ImageView SRC and background distinction _android

Source: Internet
Author: User

Before using the glide was ImageView picture settings confused (very low-level problem, it is often a problem), so went to see the ImageView, fill the foundation.

First, ImageView has two properties that show the picture, SRC and background respectively. From the name, you can know that the first is the resource (painting), the second is the background (frame).

How do you set these two values?

Background
mimageview.setbackground ();
Mimageview.setbackgroundresource ();
Mimageview.setbackgroundcolor ();
Mimageview.setbackgrounddrawable ();

SRC
mimageview.setimageresource ();
Mimageview.setimagedrawable ();
Mimageview.setimageuri ();

Of the 4 methods that set up background, the setbackgrounddrawable () of the @deprecated method is ultimately called.

Some differences:

1.SRC is the size of the original image, background will be stretched according to the size of the component.
2.SRC is the content of the picture (painting), background is the background of the picture (frame), can exist at the same time.
3.background can set the transparency, SRC cannot be.
4.scaleType only works on SRC. This text explains very clearly->scaletype detailed explanation
5. Use setbackgrounddrawable when drawing in custom ImageView. If use setimagedrawable, need to set setintrinsicheight and setintrinsicwidth, otherwise will not show, specific reason to see the source code bar.

Through this article hope to help to have the need of small partners, thank you for your support to this site!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.