How to show dynamic drawable using Picasso - android

I have some drawable generated dynamically from material design icons
Drawable qq = new IconDrawable(context, FontAwesomeIcons.fa_qq).
colorRes(R.color.qq).sizeRes(R.dimen.button_height_normal);
I want to show this Drawable using Picasso but when try to load this Drawable get an error because Picasso load accept only url for the Drawable and I can't get it or get it's Resource Id.
there any way to make that ?

I've made a workaround as I've not seen the way to set directly a dynamically generated drawable. Picasso has the "error" and "placeholder" options that they both allow inputing a drawable so if you make the load to fail the Picasso will load the drawable (with you desired transformations, for instance):
Picasso.with(context).load("nothing").error(placeholder).placeholder(placeholder).into(this)
where placeholder is the drawable you want to load

Related

How to reset the resource of image view in 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.

how to load xml in imageview using glide

I have created an gradient xml in drawable folder of my project. I want to load that xml in an ImageView using Glide. How can I do that ?
Simple loading of image in ImageView using Glide:
Glide.with(LoginActivity.this).load(R.drawable.a270).asBitmap().diskCacheStrategy(DiskCacheStrategy.RESULT).into(backgroundImage);
But if I use the same code above replacing R.drawable.a270 with R.drawable.gradient_background with a drawable xml its not working.
Please try this -
Glide.with(LoginActivity.this).load("").error(R.drawable.gradient_background).diskCacheStrategy(DiskCacheStrategy.RESULT).into(backgroundImage);
OR
Glide.with(LoginActivity.this).load(null).fallback(R.drawable.gradient_background).diskCacheStrategy(DiskCacheStrategy.RESULT).into(backgroundImage);
I doubt you are using VectorDrawable or animated drawable. Please refer this and this for more information on this.

Load dyanmic resource drawable using Picasso

I want to load multiple drawable-resources in RecyclerView and i am using Picasso in RecyclerView.ViewHolder for this task.
Picasso.with(context)
.load(imageList.get(position))
.into(imageView);
Picasso loads the drawable-resources which are in drawable folder but it doesn't load resources from other drawable.
For example if i put the drawables in all drawable folders(mdpi,hdpi,xhdpi etc) except "drawable" folder, It doesn't work.
So is there something I am missing? is it possible to dynamic reference to the drawables using Picasso?
Picasso should load mipmaps. Try forcing just one to show, like
Picasso.with(context).load(R.mipmap.ic_launcher).into(imageView);
and see if is loading. If it is, there is something with your id's from array.

rectangular box with one side diagonal

I want to create a custom View similar to this image. More specifically, the dark "number of riders" view. I don't want to use an image for background. I need a drawable xml for the background.
I am new to Android so any help would be appreciated.
The best way to do that will be to use a 9-patch drawable file and set it as the background of the TextView.
Here is how you can do that: http://en.miui.com/thread-26099-1-1.html
Or you can create an SVG and use that as background. The easiest way to do that would be to make a png image and convert it to SVG file using online converters.
How to convert a PNG image to a SVG?
There is more complicated way to archive it like drawing on a canvas and using that as background, But I would recommend you to use 9-patch file.

Android: How to use TextView in placeholder of Glide or Picasso

i am using Glide or Picasso for loading the image like
Glide.with(context).load(POST_IMAGE).placeholder(R.drawable.loading_img).error(R.drawable.bg_480_800).into(image);
Picasso.with(context).load("image url").error(R.drawable.bg_480_800).placeholder(R.drawable.loading_img).into(holder.imageURL);
In these two, i'm using image as place holder from the drawable folder. Now i want to use text inside the place holder instead of image from drawable folder.
So, please help me to load text instead of loading image from the drawable folder
Placeholder is a Drawable, so what you'll need is some kind of Drawable that is able to display text. This library does exactly that, and does it pretty well.

Categories

Resources