I'm using Picasso Square library in my android application. The app is a very simple one and shows a grid of pictures. When you touch one it opens it in full screen and when swiping to the right the next in line should be displayed.
My problem is that for every swipe, the image is loaded by picasso method:
Picasso.with(getApplicationContext()).load(Properties.IMAGE_URL + i).transform(transformation).centerCrop().fit().into(imageView);
I would like to avoid the load wait time and simply cache the next 2 images to be displayed. how would I go about doing this?
I know that picasso caches the images if they were loaded before. Is there a way to load the next image with picasso without attaching it to a specific ui element to be displayed?
There is a way to do it – use fetch(). You can get more information from this question.
Related
I've got a simple use case. I have a local image uri (content://path) that I load into an ImageView - that's step 1. After a button is pressed, the image is replaced with an image from our server - that's step 2.
My code is quite simple - or at least, I can reproduce the issue even after I simplified the code to the following:
Glide.with(imageHolder.getContext()).load(url).into(imageHolder);
The first time, this is called with a local uri (content://path), followed by a remote url (http://path.com).
Loading the local uri works just fine. The problem is that, once I initiate the load from the server (which might take a second), Glide rolls back to the ImageView's background image colour. So visually I get old image -> background colour -> new image, which is quite annoying.
Is there some sort of a hidden way in Glide to work around this?
this is because while the server image is being loaded there is a gap between removing local image and showing the new one and that gap is your problem.
one of the workarounds to this issue is to give Glide a placeholder (set your local image as the placeholder) so while Glide is loading image from server it still shows the local image and once the server image is loaded the local one goes away.
Glide.with(imageHolder.getContext())
.placeholder(YOUR_LOCAL_IMAGE_HERE)
.load(url)
.into(imageHolder);
I'm trying to replicate the functionality of Facebook's image upload. To briefly describe it you click the Photo button from the main screen of the app you are taken to an image picker that will let you select up to 30 images. Once selected the images load in some kind of list view that allows you to add a caption, remove the image from the list, or do some other Facebook-y things. If you scroll around the list can move very quickly, and if you only have 5-10 images you generally spend little to no time waiting for items to reload.
Right now I have a recycler view and am using Picasso to load the images from disk, resize them, and then display them. This works, but it's not smooth or fast. Even if I only have five or six images loaded they don't come up instantly if I scroll from the bottom back to the top. I have tried increasing the LRU Cache size in Picasso, but that didn't do anything at all. It seems like the scaled image isn't getting cached so it has to be scaled to fit the screen width every time. That's just my guess though.
Any suggestions on how to get this to run more smoothly?
I have an app that loads content from a database as well as images from the internet. I am using a RecyclerView along with CardView to display my content in a list form.
Each row has an image on the left side and text on the right.
The problem is that the text loads fast but the image takes time to load, so I want the image to continue loading in the background and then load into the ImageView object once loading is complete. I have no idea how to tackle this.
I use Picasso for this situation, but u can also use Glide and many more libraries. The documentation is pretty simple.
Try Picasso:http://square.github.io/picasso/
It's a one liner in onBindViewholder():
Picasso.with(context).load(url).into(viewHolder.imageView);
I currently have a gridview that displays some thumbnail images. The problem I am running into is that when I scroll through the images I can see the images switch from old to new as they are being replaced. So, I was wondering how I would fix this. Is there a way to load images that aren't on the screen so when I scroll the user doesn't have to see the change in images?
The best way to avoid that effect is to set the image first to null in the getView() method of your adapter. You can then check an LRU cache if the image is already loaded. If yes, then set it right away, if not then load it asynchronous as a bitmap. Set it to the view and add it to the LRU cache.
I need to make an image gallery that takes a JSON list of remote images and pre-loads them and disposes them on the fly as i scroll left or right. I cannt seem to find any examples of this other than a list of images being loaded on the fly. What I want to do is to load the next ones (left and right) while the previous one is on the screen, dumping the others as I go.
I see widget.gallery but is this suitable for this or should I use a Canvas and write my own?
Look at here. There is a ListView with lazy loading, this should show you the solution.
Lazy load of images in ListView