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
Related
I have a lot of images and I want to classify them in the drawable folder in Android Studio for easy access, is it possible?
Not possible. The only way to sort your drawable resources is by renaming them, usually with prefixes (i.e. ic_ for icons).
You can't put them in folders. However, you can control the name of them to find them easier. For example, if I have buttons coded with shapes, etc, I will name these button_name. This way, it all of my buttons are there for me to view. If I have a few minutes in a certain activity, I will do something like results_, and then all of my results images are there. Hopefully they makes sense and helps.
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 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 have a state file for buttons which worked fine until I put drawables into res/drawable-mdpi.
I had only drawable in res/drawable-hdpi but I want the app to work on all displays.
The state file is placed in res/drawable as I read it on some websites.
That way it is also done by google with the standard drawables but Ecplise keeps telling me that it can't find drawable with value #drawable/button_normal.
The drawables are definitely at their places.
So what am I doing wrong here?
Ok...there was nothing wrong with the code, drawables were not ok.
I made them again, 9-patched them and voilĂ : no comments by eclipse.
Sorry for wasting place for this.
make a folder drawable inside res and put ya pics into that folder. and you can refer to them as
android:background="#drawable/oscar"
I've made a few shapes in drawable folder, is it possible to packed them in one resource file? How?
u can take indivitual images and place them one after the other with the
android:layout_x="0px"
android:layout_y="6px" parameters..
but it is not possible by default in android
Actually it is possible, by using level-list XML element.
If you look at this post it shows you how to do it.
You can even define the drawable within the level-list