Android Performance: load images for listView - android

I'm going to develop an application which shows a ListView which each row have a seperate image (like personal picture for contacts list). It seems I have two options:
1- Store all images in Asset Folder and load image using setImageDrawable() command.
2- Store all images in Drawable Folder and load theme using setImageResource(R.drawable.xxx)
So my questions is does they differ in performance? And how can I speed up listView rendering such that images displayed in acceptable speed.

There should not much performance different to access image from Drawable or asset folder. You can see the answer too - > Android: Accessing images from assets/drawable folders
But, When you using ListView you are recreating the view . So, Where ever you store the image all the images are will not feel much different .

There are not so much differences. Just for coding pattern changes.
assets/
Bitmap files (.png, .9.png, .jpg, .gif) or XML files that are compiled into the following drawable resource.
drawable/
Arbitrary files to save in their raw form. To open these resources with a raw InputStream, call Resources.openRawResource() with the resource ID, which is R.raw.filename.
https://developer.android.com/guide/topics/resources/providing-resources.html#ResourceTypes

Related

How can i change fill color of a vector file fetched from server in android?

Is there anyway I can access the elements of vector file like fill color on the click of certain path fetched from the server. I am fetching whole vector file from the server. I have tried many library including RichPath ,VectorChildFinder, AndroidSVG but they require a vector file which is stored in res folder. It would not feasible to keep all the files in the res folder as there are many.
What I have achieved is I can parse it into a imageview but can't access the elements inside it.
Thank you.
I don't know about the others, but AndroidSVG does not require the file to be in a res or assets folder. The library doesn't include any method to fetch from a URL, but you can always fetch the file yourself and then use SVG.getFromString(fetchedSVGData).
If you don't want to handle the fetching yourself, you could use a library like Glide. It has an example of how to fetch SVGs and display with AndroidSVG.
To colour the SVG, just use AndroidSVGs ability to pass CSS stylesheet when rendering.

How to load images for different densities from server

I have an expandableListView in my activity and passing data from JSON that I get from server. Everything is working fine Except the image part.
I'm getting image path as string within JSON for different sizes (48x48, 72x72, 96x96 etc.) but unable to figure out how to assign image according to the screen density. I think I can Add these images into the corresponding drawable folder and android would do the rest. But on searching I did not find any example on how to add images in drawable folder dynamically.
If there is any way to add images dynamically into drawable folder please let me know OR suggest any other appropriate solution.
You can't add images dynamically into the drawable folders.
But you can get the device's screen density programmatically. You can use that value in your api and return appropriate image(s).
You must understand whats drawables in android by this link
and you must know that you can't put any images into them dynamically, icons and static images must be into drawables folders, for other images which you are using them into application you can get image and thumbnail
it's not possible to save in drawable at runtime.
you can't use assets folder too.
if I were you it I didn't bother my self to determine screen density. use Glide and Picasso in order to load image asynchronously.
Update :
the thing that i should mention is that, if the ImaveView is a fixed size view by dp it'll appear "the same size" on all devices as per Android's specs.
glide and Picasso read the view size by pixel and then scale the image to that size.
I prefer Glide because it has a smaller memory footprint by making some different assumptions like caching the resized images instead of the full-sized images.
Edit:
#greenapps you are completely right. it cannot be saved in assets too. try to create a directory and save drawable into that

Android: store image in database or drawable

In my app, there may be more than thousand of small image/ icon
and they will be display in views inside the list view or grid view
While I am wondering how the data should be store
1. covert to the string array and store in the database.
2. in the drawable folder (and how should the path store in the database?)
3. other better method?
A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon.
You should store the images in Drawable folder. The Drawable folder is pre-compiled. Which means that the images will be fetched much faster than from Database.

What is the effective way to store over 200 emotion icons in Android application

I have over 200 emotion icons in my application.
And I put them in res/drawable.
And it really make the drawable folder so large although each icon just 1-3K.
Is there any other good methods to store these icons instead of storing them in drawable folder?
Also, I will display those icons in grid view to let users to select.
Is it good to store all in drawable folder and put them in the grid view?
You can merge all your images in single bitmap. If you keep the size fixed, then you can use Bitmap.createBitmap() in a loop to generate a bitmap array.
Follow this tutorial on splitting bitmap.
SPLITTING/DIVIDING AN IMAGE INTO SMALLER CHUNKS/PIECES IN ANDROID
How to Split a Bitmap into Pieces in Android

Where from it is faster to load images in the ListView?

I fill the ListView from DataBase by using SimpleCursorAdapter where I am overriding getView method. By this method for each item I am loading the small image from my telephone.
Where do you suggest to store my small images (20 images x 1 kB)?
in DB (it is on my SDCARD);
in the folder on SDCARD;
in assets;
in raw folder.
Images that you are including with your project should go in one of the drawable folders, not assets or raw, for instance yourProjectFolder/res/drawable-mdpi/
You can provide higher / lower resolution images in the ldpi, and hdpi folders.
As to whether you should use the drawables folder or some form of SD storage it comes down to whether or not you may ever need to change the images. If you include them in your project drawable folder then you will be unable to make any changes to them after compile time. If you store them on the SD then you have the option to go back and download different / more pictures to use.
So it just depends on if you'll ever need to the option to add more, or change the images that you're using.

Categories

Resources