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.
Related
I want to load SVG in ImageView from Gridview Adapter,
i do this:
imageView.setImageURI(Uri.parse("file:///android_asset/ico/s.svg"));
but not work and dont show anything
I want to load SVG in ImageView from Gridview Adapter, i do this:
First, ImageView does not support SVG directly.
Second, your code appears to be loading a PNG file, not an SVG file.
Third, file:///android_asset/ is for WebView. It does not work elsewhere in the Android SDK.
You should consider switching to using Glide as an image-loader. It handles file:///android_asset/ and has sample code for transcoding SVG files. Plus, it does the image-loading work on a background thread.
Otherwise, you can use AssetManager and its open() method to get an InputStream on an asset. If that asset is a PNG, JPEG, or WebP file, you can use BitmapFactory.decodeStream() to read in the stream and give you a Bitmap back that you can use for the ImageView. You would need a third-party library to do something with an SVG asset. And, you need to arrange to do this work on a background thread, as otherwise your UI will freeze and cause users to think that your app is stuck.
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
I am working with Android Picasso Library and after setting image from drawable folder in placeholder,I am getting outOfMemory exception. Do picasso place holder image stays in memory, If yes then how to remove placeHolder image when actual image is loaded?
This happens because system try to Scale it according to density of the device .The solution worked for me is to create a folder named drawable-nodpi inside your res folder . Then put your placeholder image into that folder .
Let me know if it works .
You may try resizing your placeholder image since it might be to big and causing OutOfMemory, but it can be also more complex error not only of placeholder. And maybe it's not the problem of placeholder but of current image loaded from url which is too big? You can resize this image with below code:
picasso.with(mContext)
.load(someUrl)
.resize(sizeX, sizeY)
.placeHolder(R.drawable.placeholder)
.into(imageView);
I would like to create fragment with image as background. What I do is saving image in .png format, putting it to drawable folder and than using it as background in layout. First thing I noticed is that the view stutters, so I created different images for different densities. But I'm still afraid that in older devices with worser CPU view would statter.
Question
Do I have to use libraries like Picasso for adding images as background ? What is the best approach ?
I think that base approach of using libraries like Picasso, Glide, UniversalImageLoader is for downloading images from network, caching, decoding, smooth loading in runtime.
If you want just set background for imageView from your local resources the only thing you should consider is to do this efficiently. This is nice described by google here and should be enough for your case.
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.