我想爲ImageView設置背景顏色,當圖像視圖具有圖像資源時,它可以工作,並獲得我的背景顏色,但是當圖像鑑於沒有一個圖像資源,SetBackgroundColor不工作,什麼都不做,這是我的代碼:當圖像資源沒有圖像資源時,無法設置圖像視圖的背景顏色
XML佈局:
<ImageView android:layout_centerHorizontal="true"
android:id="@+id/favor_item_image"
android:layout_alignParentTop="true" android:layout_height="wrap_content"
android:layout_width="match_parent" android:adjustViewBounds="true"/>
java代碼:
ImageView favorImage = (ImageView) MyView.findViewById(R.id.favor_item_image);
//favorImage.setImageResource(R.drawable.btndelete);
favorImage.setBackgroundColor(Color.argb(255,255,0,0));
因此,當我評論這一行://favorImage.setImageResource(R.drawable.btndelete);我無法設置圖像視圖背景顏色,但是當我取消註釋此行時,setBackgroundColor工作正常。
請任何幫助。 謝謝
是的,你是對的,它的工作原理,謝謝! – 2012-04-18 18:04:10