I want to load the Async image loading for grid view. The image loading should be Async and should only when grid view scrolled. And when scroll up the image should be loaded from cache. Simply i need a loading style just like fb,pinterest.
Use Jake Wharton's Picasso Library. (A Perfect ImageLoading Library form the developer of ActionBarSherlock)
A powerful image downloading and caching library for Android.
Images add much-needed context and visual flair to Android applications. Picasso allows for hassle-free image loading in your application—often in one line of code!
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
Many common pitfalls of image loading on Android are handled automatically by Picasso:
Handling ImageView recycling and download cancelation in an adapter. Complex image transformations with minimal memory use. Automatic memory and disk caching.
Picasso Jake Wharton's Library
Your exact requirement in serviced by Android Universal Image Loader Library. Check out the github repository here
There is a sample code given here which shows the working of the loader for a grid layout.
Hopefully this will serve your need.
Related
I am using Fresco Image Loader in my application in which uri is loaded into SimpleDraweeView. I have a list of images, sometimes i load the same image into two different views. In this case does fresco loads the image from cache into SimpleDraweeView or does it downloads the image from the network whenever needed and also where exactly do i need to use Drawee and ImagePipeline. Please help me.
Fresco library is built specifically to address concerns like this. To answer your first question, no, the image won't be downloaded twice. It won't even be decoded twice. Fresco avoids doing any duplicate work. You should be completely fine in using the same uri in multiple views at the same time.
As for your other question, Drawee operates on an API level above ImagePipeline. Those two are not competing. ImagePipeline is to Drawee as a Wheel is to a Car. If you want to display the image you should be using Drawee and not ImagePipeline. If you need to get the actual image bytes or to do something else with the Bitmap other than displaying it, you should use the ImagePipeline.
I've been trying to create a Recycler View full of Card Views. Currently, I'm using the Recycler View from this tutorial and loading it with 14 different images. The professional quality images range in size from 134K to 242K.(Down from 8MB - 18MB)
I know that the images may be too big but, I feel there must be some way to get better performance while scrolling. Can someone point me in the right direction?
Edit: The images will be stored on the device. There will probably never be more than 20 of them.
You can use Picasso library or Android Universal Image Loader
Picasso
Android-Universal-Image-Loader
You don't need any AsyncTask.Theese 2 library handling image operations in background so you can keep scrolling smoothly. I am using Picasso in my project right now. You can add error drawable , temporary placeholder default drawable , and its so simple automatically caching.
Just use one of them in onBindViewHolder to bind any image to imageView
Load the images in a separate thread (or AsyncTask).
I have a decent android app which is using two fragments one of them is Listfragment. And my question is, can I use Asynctask to download the image and compress it to a thumbnail and then assign it to an imageview ? (Imagine there are like 100 items in ListView). Or is this even possible to call the asynctask each time ?
You don't need to reinvent the wheel. There are libraries which already can download, cache and resize image for you. For instance Picasso:
Picasso
.with(context)
.load(url)
.resizeDimen(width, height)
.centerCrop()
.error(R.drawable.error_img);
.into(placeholder);
For this task, I would strongly recommend the use of an external library.
There are many to choose from that can be used to download, display and cache images from an online source. As many of these libraries have been developed for many years, they are usually going to be better than any bespoke code you write.
I have an image that I want to download from online.
http://luxproperty.kaytami.com/platform/media/image/jpeg/2014/12/24 Repulse Bay Road.jpg
I have replaced the space with %20, so it becomes
http://luxproperty.kaytami.com/platform/media/image/jpeg/2014/12/24%20Repulse%20Bay%20Road.jpg
The image is not large and so I assume Picasso should be able to load it.
To fit my imageview, I have fit() the image, and the code is as follow:
Picasso.with(mContext).load(UrlEncoder.encode(district.getImage_urls().get(0))).fit().centerCrop().into(holder.image);
However, the image does not appear.
There is a list of 4 items, each containing an image that I load from online. three of them were loaded properly, and the remaining one (http://luxproperty.kaytami.com/platform/media/image/jpeg/2014/12/24%20Repulse%20Bay%20Road.jpg) just does not show up.
Any idea?
I am using Picasso 2.4.0, okhttp-2.1.0 have a look this
It's a bug that is reported to be fixed in the next release of the lib.
You can clone the repo of the lib and compile your own jar or wait.
I recommend you to take a look at Glide. Migrating from Picasso is quite trivial, it has better performance and it makes a nice smooth scrolling on lists.
I had the same problemm when i tried to use Picasso to load images but i used this Library
Its the simplest thing so far by me.
Compile:
compile 'com.koushikdutta.ion:ion:2.+'
Then:
//for activity
ImageView myImage = (ImageView)findViewById(R.id.my_image);
//for fragment
ImageView myImage = (ImageView)rootView.findViewById(R.id.my_image);
Ion.with(myImage)
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.error_image)
.load("http://example.com/image.png");
Hope it helps!!!
I've a ListView in which each row item contains many ImageViews apart from some content.
That is, there will be many list items, each containing many images.
In order to not to hold user unnecessarily, I'm showing the content first & then downloading the images asynchronously.
Currently, for each image I'm starting a new AsycTask.
Although, it working alright, but this not a good approach.
In place of this, what should I use?
use this library, best in android for image loading..
https://github.com/nostra13/Android-Universal-Image-Loader
Your scenario seems to fit exactly to use LazyLoading of images. This basically loads images in the background and shows them as soon as they're loaded.
You might want to see this:
Lazy load of images in ListView
An alternative would be using a ThreadPoolExecutor with the images to load, but the above works pretty well and is recommended.
Try using the library
http://square.github.io/picasso/
Many common pitfalls of image loading on Android are handled automatically by Picasso:
Handling ImageView recycling and download cancelation in an adapter.
Complex image transformations with minimal memory use.
Automatic memory and disk caching.