Remember the difference between ImageView background and SRC thoroughly

The sample code

<ImageView
    android:id="@+id/iv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_launcher"
    android:src="@drawable/ic_launcher" />
Copy the code

The difference between:

(1) Background will stretch the Drawable according to the width and height of the ImageView control; SRC keeps the size of the Image; background is foreground; SRC is foreground. ScaleType only applies to SRC.

Background:

Background is a View property, specifically android.r.tyleable #View_background, which takes effect when the View#draw(Canvas Canvas) method is used. In the View#draw(Canvas Canvas) method, the View#drawBackground(Canvas Canvas) method is first called to draw the background. OnDraw, dispatchDraw, onDrawForeground and other methods will be called.

src:

SRC is the attribute of the ImageView, in particular android.r.table_imageView_src, which is used to draw the corresponding mDrawable attribute in the onDraw method, the specific call time is after the background draw.

reference

The difference between SRC and background in Android _android