change background of an ImageView (the old image stays there!)
how can I change the background of an ImageView from java? I have an ImageView and at a certain point I need to change the image that it displays (set in the styles). I tried to do it like this:
placeHolder.setImageDrawable(myDrawb);
开发者_开发问答
but it looks like the old image remains there and it is partially covered but the new one (which in my case has different shape).
hope you guys can help!
cheers
You don't need to touch the XML to use src instead of background!
An ImageView can display two drawables! One in the background and other in the foreground. It seems that you are always changing the background image.
Instead of setBackgroundResource(resId)
use setImageResource(resId)
to change the foreground image!
Clear the background image with:
placeHolder.setBackgroundResource( 0 );
Alternatively you should set the Src
of the ImageView
in xml instead of setting the Background
. I think this is the "right" way anyhow.
精彩评论