How to reset the resource of image view in android? - android

Trying to change the image in imageView dynamically based on the status.
Image changed successfully but problem is walk image overwrite on the run image. I want to clear the existing image and then set the new image.
status_image.setImageResource(if(runningState == RunningState.FAST) R.drawable.ic_run_fast else R.drawable.ic_walk)

Just call it with a "0" parameter before doing anything else:
status_image.setImageResource(0)

Nullability of drawable content is your friend, AndroidDocs nailed it: setImageDrawable
So in your case statusImageView.setImageDrawable(null)

Try to set the ImageView to transparent. Then change it back to the resource you want.
status_image.setImageResource(android.R.color.transparent)
Another option is to use some third party lib to handle the images for you as well, like Glide, Fresco, or Picasso.

Related

I can't make an image transparent on Android?

I tried everything, but it didn't work. Please help me
All you have to do it to download a transparent img of a cart and adjust the width and length you can also download it with the link below 👇👇
https://www.flaticon.com/free-icon/shopping-cart_833314?term=cart&page=1&position=3&page=1&position=3&related_id=833314&origin=search
If you have taken this image from your storage then you can simply convert it's background transparent by using any background remover tool online such as this one:
remove background

Set an image between coordinates

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

com.squareup.picasso returns empty (gray) image after resize

I have an imagepicker in my app and after I picked an image from an Intent.ACTION_PICK I wan´t to show it in a small thumbnail.
For image resizing and so on I use Picasso like this:
screenshot.post(() -> Picasso.with(this)
.load(Uri.parse(newState.attachmentUri))
.resize(screenshot.getWidth(), screenshot.getHeight())
.centerInside()
.into(screenshot));
Now I get Bugreports that this thumbnail remains empty (light gray). I couldn´t recreate the issue until I found an image in my gallery that creates the same issue.
I found out that this are images that where made with an effect called "focus effect" of the google camera. I cross-checked this by making several photos with this effect and several without. I can reproduce the error with the images with effect and the images without effect are working properly... What could be wrong here?
When I remove the resize all works fine..
Can you help me here?
Best regards
Artur
This happened for me when the ImageView had android:tint set to a value in the XML layout.
I guess that some parameters prevent the image from displaying correctly, which include the tint and maybe the resize parameters (according to the comments on your question).

How to get the name of drawable through resource id?

I am trying to make the bitmap and for this I need the drawable name such as:
overlayScaledBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.monkey);
This is working fine But my problem is that I can not do this same thing when a user selects a picture from a list because I have done this statically. As you can see I have wrote R.drawable.monkey. So its means every time it is going to create bitmap with monkey image.
But it is not the case, the user selects image which gets fixed into the image view. Now I want to get the ImageView as drawable. If it is possible then it could be dynamically and would be easy to handle. Any idea How I can get drawable of ImageView to use in bitmap scaling? please help
You could create an enum object containing all refs to the bitmaps and an id.
But another way is using getTag() and setTag() on the resources to identify by.

How can I make an empty/invisible bitmap?

Is there any way to create a bitmap that, when you use it in on a view in the setImageBitmap method, it looks like no image was actually set at all?
EDIT: To clarify, I want the bitmap to not be visible, or it can be visible, as long as its nothing, as long as the user cant see it im happy.
EDIT2: I cannot use setVisibility because my ImageView also has a setBackground attribute that I want to remain visible. If I set the view to invisible, the background AND the bitmap image are affected, and I dont want that. I only want the bitmap image to be invisible.
You could call imageView.setImageBitmap(null) to remove the current image and keep the background.
You could make a 1x1 pixel bitmap which is nothing but empty canvas (in photoshop perhaps), then use the draw9patch tool to make it stretch.
EDIT: If you just need it not to draw, you can call setVisibility(View.INVISIBLE) on the view like so:
imageView.setVisibilty(View.INVISIBLE)
← Image is here
above is a 50X50 transparent image created in photoshop download and use it,

Categories

Resources