I created an XML layout for my project with an ImageView in it. I add a default image for 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.
Related
I have 4activity and I want to set an image for these activities, I set the android:background="#drawable/background"property but it scales the image but I want this image set as a title image(set the background image size). I don't want to use ImageView because I want other views locate on the background Image.
how can I do this?
Here is an example of what I need to do:
First of all I convert the image into bitmap and then set it as background to a relative layout. And i know these four coordinates.
Then how can I get the image inside the box and set it to another layout as background?
Try to use Picasso when you are dealing with Images.
This is the link
I have an ImageView in a RelativeLayout. The background of the ImageView is empty and the srcCompat is linked to my image in the drawable folder. In the layout Preview everything looks fine but when I test the app in an emulator or real smartphone my ImageView is empty and I can't see the selected Image. When I link the background property to my image in the drawable folder and delete the entry from srcCompat my picture is shown by the app. The problem is I can't scale the image if its set as the background of my ImageView. Can someone help me?
Thanks and sorry for my bad english!
The difference is that srcCompatis the actual content of your ImageView. You can, for example set backgroundColor to red, and give a drawable to your srcCompat. The result will be a red background and the given drawable above it.
Hope this helps.
Use src in place of srcCompat.As it srcCompat attribute is actually defined within AppCompat library. For more details
i have some image (either resource image or bitmap image)
what is the major difference between showing them in ImageView or set them as background in LinearLayout.
any difference in Quality or Memory usage ?
what is the major difference between showing them in ImageView or set
them as background in LinearLayout.
When you set a background to a layout.It may re-size and change the shape of the image.So it may change your expected output view.
ImageView is specially designed for setting images and it has extra features like android:scaleType, you can set the exact image and use function like crop.
any difference in Quality or Memory usage
Image view is a view and it will reduce the computation of loading the layout each time while using a layout for this porpose.
In my app I am getting image from URL and showing in an ImageView. I get a circle shape(blue color) image which is in a square(white color) background. I want to show my image just as a circle ..How to remove or hide the extra white color in that image within my app?
Below is the image for reference:
You should first remove the white part of image in an image editor like Photoshop or Gimp. Making background transparent won't work because white part is not background, It's in image.
Alternatively, You can create a round Imageview if you want your square images to be shown as circular (e.g. profile pictures on Google+). There is a working code snippet here for rounded ImageView How to create a circular ImageView in Android?
Alternatively, if you don't want to use this snippet, you can use a library that will make it easy to create rounded ImageViews. see this
https://github.com/vinc3m1/RoundedImageViewā€ˇ