更改ImageView源 - Changing ImageView source

問題:

I have an ImageView with a source image set in the xml using the following syntax: 我使用以下語法在xml中設置了一個帶有源圖像的ImageView

   <ImageView 
      android:id="@+id/articleImg"
      style="@style/articleImgSmall_2"
      android:src="@drawable/default_m" />

Now I need to change this image programmatically. 現在我需要以編程方式更改此圖像。 What I need to do is delete the old image and add a new one though. 我需要做的是刪除舊圖像並添加一個新圖像。 What I have done is this: 我做的是這樣的:

myImgView.setBackgroundResource(R.drawable.monkey);

It works but I noticed android stacks the new image on top of the old one (dont ask me how I found out it's not relevant for the discussion :). 它工作但我注意到android將新圖像堆疊在舊圖像之上(不要問我是如何發現它與討論無關:)。 I definitely need to get rid of the old one before setting the new image. 在設置新圖像之前,我絕對需要擺脫舊版本。

How can I achieve that? 我怎樣才能做到這一點?


解決方案:

參考一: https://stackoom.com/question/CTte
參考二: Changing ImageView source
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章