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.
Related
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
I want to add my image in Drawable s All files according to its size with single image
how it can perform .
Actually I retrieve images from DB Server..While no need to define Server logic in your Answer
You can't add resources in your app at runtime. So you will not be able to add image in your drawables folder.
However you can store in it in a file in your app directory using Context.openFileOutput.
I'm new to development and I'm stuck at a point where I don't know what would be the best possible solution.
I have a list of 26 images saved in the drawable folder. Lets say a to z. When user clicks on the right side layout they should navigate forward and if the user clicks on the left side layout they should navigate backwards.
My issue is that these are images and their IDs as retrieved by android are random int values. I can't use that to compare which letter of alphabet should be displayed next.
How do I go about this problem?
If I name the images a.png, b.png, c.png... How do I retrieve the name later from the ID?
Will I be able to store the drawables as a key value pair using collection framework?
You can get the name of your resource by
String resourceName = getResources().getResourceName(resId);
You can store all the image ids in an array.
For example,
int images[]=new int[]{R.id.a,R.id.b,...,R.id.z};
Then you need to maintain the position in array of the current image every time you navigate.
For example change position as
pos=(pos+1)%26;
for next image and
pos=(pos-1)%26;
for previous image
and then use
setImageResource(images[pos]);
if its an ImageView or ImageButton, or using getResources().
You can retrive the ids of images in drawable folder like this...
int imagekey=getResources().getIdentifier(url.toLowerCase(),"drawable",getPackageName());
where url is the name of the images in the drawable folder
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
I am a beginner developer and I am a little confused about drawables and bitmaps. From my current understanding:
-Bitmaps are like empty images (without a type yet?)
-Drawables are images that I can draw on them
What I want to do in the first place is to open a red image I made and then draw on it. How can I do that?
Also, all drawables must be placed in the 3 drawable folders, right?
By the way, what's the different of "assets" and "res" folder?
Thank you in advance.
A drawable might be a bitmap, but maybe a shape
drawable is more general
assets holds file data
res holds (xml) defined data
Just some answers to your bunch of questions