一、ImageView
的 src
属性与 background
的区别
-
background
通常指的都是背景,而src
指的是内容。 -
当使用
src
填入图片时,是按照图片大小百接填充,并不会进行拉伸,而使用background
填入图片,则是会根据ImageView
给定的宽度来进行拉伸。<!-- ImageView 根据内容适应宽度 --> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ic_launcher"/> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> <!-- ImageView 限制宽度 --> <ImageView android:layout_width="160dp" android:layout_height="80dp" android:background="@mipmap/ic_launcher"/> <ImageView android:layout_width="160dp" android:layout_height="80dp" android:src="@mipmap/ic_launcher"/> <!-- ImageView 有图片有背景 --> <ImageView android:layout_width="160dp" android:layout_height="80dp" android:background="#ffc" android:src="@mipmap/ic_launcher"/>