I have to show 64/64 bitmaps in a grid of 1100/1100 but the scrolling is not smooth. What is the optimum way in displaying such ammount of image data?
This is just too much memory consumption for an android app.. I don't think you really want to load all of those at the same time. I would rethink the requirements first.
There should be a solution that still satisfies the user and does not load that many views into memory. I don't know what is the use-case here, but I would suggest implementing something like paging. Load a limited amount of items, and only if user wants to see more, then show progress bar and load more.
E.g. you can load more if user scrolls to the last item, or just create a button like "Show more". I'm not sure which solution will be okay for your app. Also, I would actually load new items into the same GridView replacing previously loaded bitmaps, because each of them requires a lot of memory. You can always control the scrolling position programmatically if needed.
I have a GridView with thumbnail images loaded in a separate thread. After all the thumbnails are done loading, if I scroll the grid view it's consistently slow (~5fps), until I scroll a few rows down, then it immediately scrolls extremely fast (~30fps) even if I scroll all the way up again.
If I then repopulate the gridview, it's slow again until I scroll down some more. It's not an issue of recycling the views as I am already doing that.
(Update: uploaded the correct slow trace image)
I tracked the issue to an internal view draw call. Here is the Android Studio trace for when it's slow:
And here is the trace for when it's fast:
It's clear the guilty method is android.view.ThreadedRenderer.draw(), but this is an internal call and I can't test further. From the trace, my understanding is that it's not the drawing that is slow, as the android.view.ThreadedRenderer.updateRootDisplayList() which eventually calls android.widget.AbsListView.draw() finishes just as quickly in both traces. So it must be the rest of the android.view.ThreadedRenderer.draw() that is causing this.
Looking online I found the ThreadedRenderer.java class
Things I've tried:
Forcing hardware rendering on the gridview made no difference.
Forcing software rendering on the gridview made the list always scroll very slowly.
Any ideas why this could be happening?
Well, the reason that it's a lot faster to scroll after the first time is that Android is recycling views. This means that it's taking the most time to construct the views initially.
I think you're going a bit too deep. You should check to make sure you're not downloading the thumbnails synchronously during draw. Try removing the code that downloads the images, or set the URLs to "". Essentially, try stripping down your thumbnail view until you can pinpoint what the issue is. This should help set you on the right track.
I had a similar problem recently.
You need to check the number of Layouts in your xml file.
The more relative or linear layouts you have on your scroll view the more slow it gets.
Post your xml file less see.
I have a GridView that displays images (7 columns of images that are 166dp x 249dp) that are all the same size (there are over 150 images), and I'm using the view recycling mechanism through the view holder pattern by way of an adapter. My views are all simply ImageViews. There isn't much going on that should be slowing the scrolling on this widget (there are 21 images on screen at a time), but the thing just scrolls so choppy. What can I do to speed it up?
I spoke with some of the boys at Google during the last Google Developer Lab and they told me that GridView is not maintained very much, and that I should use ListView, laying out the rows myself in code to make a grid. This is what I did and it's now lightning fast.
I have a very large image (a map) that I need to display. I already have the image in "tiled" format - 256x256 pieces.
Also I got tiles for several "zoom" levels.
At the moment the issue is to display the deepest zoom level, where you'd have really a lot of tiles.
For example, a medium sized map will contain 4 rows and 26 columns of tiles for deep level.
I tried approaching the problem using a 2 dimensional scroll view and image views inside it - 1 per tile.
The problems is that it crashes. When I try displaying 4 rows and 20 columns it doesn't crash, obviously it's a memory issue.
So the question here - how to display all that, taking into account limited phone RAM.
I do understand there should be a way to dealocate memory for images that are out of sight, and only display those which are currently in visible area of the scroll view, but I don't know how to do that.
Would be happy to hear any clues or maybe there's alternative approach to these things.
Thanks.
I think you might better use the grid view instead of arrays of scroll view (but I am not sure if it support side/updown scroll at the same time.
And then in your adapter, override the getView method. There you can control the recycling of your images.
The project I am doing also have issues with image and RAM, what I am basically doing is like:
image.recycle();
System.gc();
I tried doing the above stuff like 50fps with the image is like 800x400x32bit and still not running into out of memory issue. But if I take away the System.gc(), it crash immediately.
Hi I am using the gallery for displaying images. But the gallery has an end. I don't want this behaviour; I want to repeat the images again and again on both sides of the gallery. Is there a way to display the gallery elements as a circle?
I wrote a tutorial on how to create circular gallery.
Read it in my Blog Post here:
http://evgeni-shafran.blogspot.com/2011/08/tutorial-custom-gallery-circular-and.html
Here is what i did:
In the adapter i used, i made him think he have a really big element count.
and then each element position= position%element.lenght
and then i made the first position in the middle.
so what happen is this: (lets do it for 3 elements, you can have what ever amount you like later)
This is how the adapter see the elements:
1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3
now you tell him that the first element is in the middle:
1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,->1<-,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3
if you make it a really big number, the user can scroll a lot before getting to the end.
Hope it helped you.