ImageView的background属性与src属性的区别

ackground 就是背景, src 指的是 ImageView 要显示的图像

 
  
  1.     <ImageView
  2.         android:id="@+id/dummy_left"
  3.         android:layout_width="wrap_content"
  4.         android:layout_height="wrap_content"
  5.         android:background="#0F0"
  6.         android:contentDescription="@string/hello_world"
  7.         android:scaleType="fitStart"
  8.         android:src="@drawable/ic_launcher" />

背景就是在后面的东西,不会前来干扰你前面的 src。

之所以有这两个,是考虑到src如果是PNG格式等有透明属性的图片的话,就会在透明的地方显示出设置的background的背景,而不是黑色或者其他系统默认的填充色等。这样也是有助于美观的

猜你喜欢

转载自blog.csdn.net/smach1991710/article/details/12960077
今日推荐