I am loading an image from memory into a RecyclerView. Not api call. From phone memory.
Each item in the RecyclerView has an image.
The images are loaded only when i scroll to them. Now the problem is, when i scroll fast to the 10th item, all 10 items are loading. When i view the 10th item, the 1-8 items are not visible in the device screen yet they are loading. How to prevent this. So when i see the 20th item, it is taking around 1 minute to load.
What I want is, load only visible images. When i scroll fast to the 20th item, load only the 20th item. 1-19 and 21-... should not load
Try not to load the image in original size in RecyclerView. This severely freezes the UI.
It is better to use thumbnail images to display in recycleview.
Consider the following example:
Glide
Glide.with(context).load(image_file).thumbnail().into(imageView)
Related
I'm using Glide v3.8.0 (not v4) to load Image in to ImageView in an item of RecyclerView, and there is a bit problems: every time scroll the RecyclerView up or down, Glide load the Image into ImageView that already been loaded before, and the bad result is scroll is not smooth because it keep reload Image every time I scroll to, I don't want to reload an image that completely loaded. I have found some same questions but still have no right answer to this problem
This is my code to load image into RecyclerView item
Glide.with(mContext).load(function.BitmapToByte(function.GetBitmap(currSong.getData())))
.diskCacheStrategy(DiskCacheStrategy.ALL).error(R.drawable.noteicon).into(holder.coverimg);
Try load it by file name
Use something like string varible so let glide know that the same image loaded before
I had this problem and i fixed it using
recyclerview.setItemViewCacheSize(50);
This way not all old items will be recycled
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 need to display a list of items each with text and various number of images.
I'm currently using a ListView with custom adapter to show these items. And for each item, I used a HorizontalScrollView with a LinearLayout in it to display the images. In the getView method of the ListView, I read the image URIs of each item and dynamically create ImageViews, then load the images asynchronously. I used a ViewHolder to hold the LinearLayout which contains all the ImageViews of each item.
The problem is, if I scroll down the ListView and scroll back, I'll lost the content of the item, which means I have to load the images again. And most of the images are too large and loads very slow. Actually on my app the screen can show only about 2 or 3 items once, so the scroll happens very frequently.
I have some ideas to improve this, but I'm not sure whether one of them will results better.
Since I'm just showing a thumbnail of each image, maybe I can save the thumbnails into a temp dir and load them dynamically, loading small images will be much faster. And I might have to clear that temp dir when it gets large.
I have at most 9 images for each item, so it might still be slow even if I cache the thumbnails and scroll frequently. And maybe I have to show the list manually instead of using ListView, so each item will not be reused, and the load will happen only once. But, the list will grow large in the future, if I preserve like 100 items in the LinearLayout my app may still crash.
Other better options...
Any advice will be helpful! Thanks!
You can use LazyLoading to display your image. You can use Universal Image Loader for this purpose. What lazyloading does is download an image once, cache it and display the image from cache during subsequent requests.
I have a custom GridView, in which images are loading from the database. If I load all the images before setting the adapter, then it takes too much time as there are more than 25 images (images are of size 30-35 kB each). If I load images one by one, then i need to set adapter after every image. And during loading of images one by one, when i scroll down, it moves to the top when new image is set...
I want my images to be load one by one, but if i scroll down then it should not move to the top when new image is loaded.
I sounds like you aren't using a background task to load the adapter. I would create an asynctask that is inside of an adapter and then call a new instance of the asynctask on every getView() call. It will then load each image one at a time, but also shouldn't move the view every time an image is updated. You can also use the same technique to add in a placement image while they are being loaded.
In my app,i have a listview with image and text.when the user clicks in the listview,the image in that row will change.the problem is when user scrolls the listview.the changed image is not showing.but later it is appearing...please provide me a solution or code to avoid this.
thanks in advance..
What's the size of the images that are used for each item in the listview.
When scrolling the image needs to be redrawn and if the images are of a larger size it can take time to redraw.
Make sure the images are only as big as they need to be for the item