Issue
If my application is showing a ListView and the ListView has ListViewItem that shows few pieces of info including images, are these images cached?
In other words, If my ListView shows 1000 items and each item has one image in a layout like below and that image is located in my Resources/drawable, will the image be loaded 1000 times (and therefore consume 1000 x image_size of memory) or will it be cached and loaded only once for all 1000 images (and therefore consume only 1 x image_size of memory)?
+--------------------------------------------------+
| | TEXT |
| IMAGE |--------------------------------------|
| | TEXT | TEXT |
+--------------------------------------------------+
Solution
If my application is showing a ListView and the ListView has ListViewItem that shows few pieces of info including images, are these images cached?
Every time you load an image and display it in an item (the item should be visible), it will consume 1 x image_size
of memory, when you display 10 item in screen, it will consume 10 x image_size
of memory, but when you have 1000 item item to display, that's another case. If you just display these image and didn't use any ImageLoader
logic, it will coasts a lot of memory and as a result, if will result in OOM.
You should write own ImageLoader
logic, or just use libraries that have been around for some time that have almost perfected this. For example you could use
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.
Since it's a java lib, you can use Binding Library to use it in Xamarin.
Answered By - York Shen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.