Android ListView image resize - android

I have a lazy-loading ListView populated with images gotten over the network. The list rows are set to wrap_content, so once the image loads it resizes and the full scale image will be displayed. It looks great when scrolling down, but when scrolling up the rows resize and force the bottom rows off the screen. How can I prevent this jumpy scrolling while scrolling up?
----- EDIT:
The images are comics of varying sizes. Some are 2 or 3 frames where they aren't very tall. Others are single frame comics where they are much taller. The image needs to take up the full width and the height should not cut off any of the comic.

Assuming all images downloaded are expected to be around the same size, a good solution most developers use is to use a "dummy" image until the real image is loaded. This image will exist locally so it can be loaded almost instantaneously. In the getView method, show this dummy image until the real image is downloaded, and then simply replace it. This will prevent your rows from resizing.

you have to see this link It downloads images in the background thread. Images are being cached on SD card and in memory, It decode images with inSampleSize to reduce memory consumption and also try to handle recycled views correctly. Play a fake image when image are not completely downloaded. "sorry fo the music!!"

I figured out the solution. When I receive the image, I get the width from the parent then set the height of the image view to parentWidth * bitmapHeight / bitmapWidth. That way the resizing occurs as the row's view is created and the list doesn't jump around as much once I know the size of the bitmap.

Related

Loading images into big size imageviews

I know that ,according to android docs, that if you have a big image. Then you scale it down to size of the image view you are loading it to (using the decodeResources and Options class).
Now my question is, lets say you want to load background picture and the source image is of similar size, do you just load the image? Or do you actually scale it down a bit and then using the FITXY to stretch it?
I am trying to avoid Out Of Memory exceptions here
Thank you

Android Volley with Image Caching

Currently I'm working with an application where one activity holds a list view with image and text for each row. I'm downloading the images using the volley. When the list view item is clicked the app will switch to a another activity with a detail view where a large version of the clicked image will show. For the both time I'm using NetworkImageView.
Images are loaded in the list view with caching. But the problem appeared on the detailed view. The images are showing from the previously loaded cache with low resolution. I want to load a good resolution image on detailed view which will cache the image separately for large view.
For the both screen image url are same. How to do that ?
Thanks in advance.
First thing is a bit obvious - make sure you images are at the wanted quality.
If that's the case, you'll probably want to load the image "manually" using the ImageLoader class, as the NetworkImageView by default, optimizes the size of the Bitmap it creates to be the size of the view itself. So what happens is, you first load the thumbnail view which is small, and the saved Bitmap is created in that size instead of the original image size. Then, when the bigger view requests the same image, the cached version is returned which is a small Bitmap, and the view scales it up, creating the low-res appearance.
Try using ImageLoader.get() with the width and height appropriate to the bigger view in the detail screen.
The other alternative is to load 2 versions of the same image.

Draw a big image in center_crop type

I have a big image(about 2Mb 1024 * 540 ARGB8888) which is got via net. This image will be shown in a ImageView which is 800px width and 400px height in CENTER_CROP scale type. And there are 12 this kind of ImageView in a listview.
My question is:
Does android load the whole image into memory in CENTER_CROP mode cause it is very slow when I slide the listview. Maybe I should clip the image before setImageBitmap()? Which is the efficient way?
Read the information from the link bellow. It will help you better to understand how to work with bitmaps in android and even in ListView. You should cash images so you will not download them anytime the ListView is refreshing.And yes,android loads all the image and after that centers it and crops,what you should do is to load in memory only a thumbnail of the all image and display it and not all the image. And as i wrote, you should cash them.
Android Bitmap managing

ListView items. Handle images with huge height

I have listview items with simple View inside, and i need to display image with huge height in it. I have cache system which can split large image into smaller ones.
Question:
What is the best way to handle displaying large images in one listview item?
Sure i can add some views to item at runtime(10 view 1000px height for example), but i think that i will get out of memory.
My point is to make my app display image like 9gag app.
9gag app
9gag view hierarchy
Do not load large bitmaps to memory consider loading a smaller version into memory, set inSampleSize to true in your BitmapFactory.Options object. For example, an image with resolution 2048x1536 that is decoded with an inSampleSize of 4 produces a bitmap of approximately 512x384.
Use these common guidelines for loading large bitmaps

2 issues with android bitmaps

I have a ListView, with about 50 rows. Each item has an image. Sometimes, the images are downloaded, but sometimes, I just show a specific image from app resources.
Issues:
Sometimes I just show about 20 images from resources for my items
that all of the are the same image .it means I just show an image
for 20 rows that all the same. is it loading a bitmap an take the
amount of ram for each item ? or it just load an image and show it
for other items ?
The imageview's size for each item is 100*70 dp . so I want to do
something , like re sizing or reducing the image dp before I bitmap
them and show them in my app, so I can reduce the amount of ram they
takes . Is it possible ?
Thanks
Showing same image multiple times
If you set all the image as same Drawable (variable), you got from resources, Only 1 bitmap Drawable resides in RAM. Also, ListView recycles its rows, it does not really create 20 rows with all 20 Bitmaps loaded in RAM.
Setting DPI of images
BitmapDrawable class can automatically decide DPI for rendering, that's why it asks for Resources in its constructor. Or you can call setTargetDensity(int) later. NOTE: Changing DPI is not exactly same thing as Scaling an Image.
Loading scaled down images
This will definitely save RAM, Read Answers on how to load scaled down images.

Categories

Resources