当前位置:网站首页>彻底记住ImageView的background和src的区别
彻底记住ImageView的background和src的区别
2022-06-11 07:47:00 【tinyvampirepudge】
彻底记住ImageView的background和src的区别
示例代码
<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" />
区别:
①background会根据ImageView控件的宽高,拉伸Drawable;src会保持Image的尺寸
②background是背景,src是内容(foreground),他们可以同时存在。
③ScaleType只会作用在src上面。
background:
background是View的属性,具体是android.R.styleable#View_background属性,它的生效时机是View#draw(Canvas canvas)方法。
在View#draw(Canvas canvas)方法中,会先调用View#drawBackground(Canvas canvas)方法来绘制背景。
接着会调用onDraw、dispatchDraw、onDrawForeground等方法。
src:
src是ImageView的属性,具体是android.R.styleable#ImageView_src属性,它是在onDraw方法中绘制对应的mDrawable属性的,具体调用时机在background绘制之后。
参考
The difference between SRC and background in Android _android
边栏推荐
- Remote office experience sharing | community essay solicitation
- [cluster] lvs+keepalived high availability cluster
- [IOT] project management: how to build a better cross functional team?
- 【CodeForces908H】New Year and Boolean Bridges (FWT)
- Database connection pool and bdutils tool
- About static keyword
- Switch statement
- C language function stack frame
- 欧拉定理及扩展(附证明)
- Second remaining learning notes
猜你喜欢

Understanding of Poisson distribution and Poisson process and Erlang distribution and their relations (important theories in queuing theory and operational research)
![[IOT] project management: how to build a better cross functional team?](/img/df/28dbf0f7ba75d1bb3469cc15e70538.png)
[IOT] project management: how to build a better cross functional team?

C language Yanghui triangle code

About static keyword

SOCKET【5】- struct linger 用法

Tidb Cloud est en ligne sur le marché Google Cloud pour permettre aux développeurs du monde entier d'utiliser une nouvelle pile de bases de données htap en temps réel

Flask页面的分页

C language to achieve three piece chess (not artificial mental retardation ha ha ha)

Tutoriel de démarrage bladed (vidéo)

TiDB Cloud 上线 Google Cloud Marketplace,以全新一栈式实时 HTAP 数据库赋能全球开发者
随机推荐
Collation of basic knowledge of intermediate development of Andrews (for interview)
Modular linear equations (Chinese remainder theorem + general solution)
C language three chess games
[atcoder2307] tree game
Zero foundation self-study SQL course | union joint query
Opencv for face recognition
[atcoder2000] leftmost ball (dp+ combination number)
YUV数据的裁剪与重叠
【AtCoder1981】Shorten Diameter(图论思维)
Introduction to operations research
2022.6.6 特长生模拟
C. Manipulating History(贪心/哈希/思维/好题)
欧拉定理及扩展(附证明)
C language - Growth Diary -03- function definition and function prototype declaration
Import on CSDN MD file
TiDB Cloud 上线 Google Cloud Marketplace,以全新一栈式实时 HTAP 数据库赋能全球开发者
【IoT】智能硬件:如何获取硬件产品的wifi信号强度
The solution of "no startup device" after running Bochs
C# 微信上传Form-data
Deux diplômés, la Banque a externalisé le travail d'essai pendant plus de quatre mois. Parler de vrais sentiments...