当前位置:网站首页>Thoroughly remember the difference between ImageView background and SRC

Thoroughly remember the difference between ImageView background and SRC

2022-06-11 07:55:00 tinyvampirepudge

Remember thoroughly ImageView Of background and src The difference between

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" />

difference :

①background Will be based on ImageView Width and height of control , The tensile Drawable;src Will keep Image The size of the
②background It's the background ,src It's the content (foreground), They can exist at the same time .
③ScaleType Will only work on src above .

background:

background yes View Properties of , The concrete is android.R.styleable#View_background attribute , Its effective time is View#draw(Canvas canvas) Method .
stay View#draw(Canvas canvas) In the method , Will call first View#drawBackground(Canvas canvas) Method to draw the background .
It will then call onDrawdispatchDrawonDrawForeground Other methods .

src:

src yes ImageView Properties of , The concrete is android.R.styleable#ImageView_src attribute , It's in onDraw Method mDrawable Attribute , The specific call time is background After drawing .

Reference resources

The difference between SRC and background in Android _android

原网站

版权声明
本文为[tinyvampirepudge]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110747211058.html