set new Image on ImageView
I created an XML layout for my project with an ImageView
in it. I add a default image f开发者_StackOverflowor imageView
. Now programatically I am getting that imageview
and trying to change the image source using imgView.setImageBitmap(newbitmap);
.
The problem is that both images are showing - the default image displays behind programatically added one.
I tried:
imgView.setImageResource(0);
imgView.setImageDrawable(null);
imgView.setAlpha(0);
imgView.setImageBitmap(null);
...but the default image is still visible.
If you are setting the background of the ImageView
in the xml file, then it will remain until you clear the background. ImageView
is odd in that it can display two images, background and source. Use the attribute android:src
to set the source image and 'android:background' to set the background. All the methods you described will replace the source image but keep the background unchanged.
精彩评论