I am creating an app using android studio.
i created the assets folder and created sub directories under it for each activity i am using (each one has a different set of images).
But on the other hand i want to support multiply screen resolutions which as i read is supported using drawable folder's, also drawable doesn't support sub directories.
I am using API 19 at the moment.
Putting all the images in drawable folder will be a bug mass.
How can i achieve my goal of order in my images and supporting multiple screen resolutions
Thank you in advance
there are subfoldes in drawable. take a look at this http://developer.android.com/guide/practices/screens_support.html
The drawables folders allow you to save various resolution versions of an image into separate folders. The OS will choose the right asset based on the device screen density for you when you ask for #drawables/image_name. /assets is more like a normal file directory. In general if you pull from assets you need to handle resolution differences on your own.
Related
I've created five folder for hdpi,mhdpi,xhdpi,xxhdpi,xxxhdpi,by using android srudio builtin option in these folder one file is working good on dofferent screen sizes but when I want to create new resource file in these folder that's not working what should I do.
I am following the tutorials in the Big Nerd Ranch book for android but that book is structured for Eclipse + ADT.
I am trying to add an arrow icon to a button and I have folders (drawable-hdpi, drawable-mdpi, drawable-xhdpi) that contain sets of identical images. Ideally I would like these folders to appear in the drawable folder but whether I copy and paste or drag these folders it doesn't seem to work. They appear in the packages section instead, but when this happens I can't seem to reference them from xml files in the layout folder.
The best I can do is drag/copy the files (not the folder)into the drawable folder, in which case they stay there and I am able to use them. The problem with this is I can have, at most, one pixel density for the set of images that is in there. The only way I can think of is if I change the names of all of them so that the problem of overwriting is gone.
However in the mipmap folder in the ic_laucher.png folder there are four files of the same name, except there are greyed out density descriptions beside them. How is this done?
What should I do?
As you can see I have now added the images using the file system. I am still unable to reference these using the resource name however. I am still not sure why.
What you are seeing in the mipmap "folder" is just some UI magic. The Android project view in Android studio will combine all resources with the same name into a single entry like you are seeing for ic_launcher.png to make it easier to view your resources.
Behind the scenes, this still uses different folders on disk. If you open up your project in Windows Explorer, you will see separate folders for mipmap-xhdpi, mipmap-mdpi, etc.
The same is true for your drawable folders. You still want to keep your images in separate density-specific folders on disk. Android Studio will then display them to you as if they were all in the same drawable folder in the Android project view. You cannot physically move your density specific folders beneath the drawable folder.
How do the drawable folders work nowadays?
I used to be able to just add folders named drawable-mdpi and such to get image resources, but this feature has seemingly disappeared. Image assets doesn't allow me to add image assets that aren't icons without messing them up and manually adding the drawable folders I need doesn't work any more as android can no longer find the resources.
How does android look for drawables now and how can I add prescaled images to my projects manually?
I recently installed one more Android SDK to Android Studio, the SDK version 4.4 (API level 19), and after using it with my project, it added a set of mipmap folders in the project's res folder (res/mipmap).
I neither understand why, or how to use them.
I read another question about it here on SO.
The answer to it said that:
The mipmap folders are for placing your app icons in only. Any other
drawable assets you use should be placed in the relevant drawable
folders as before.
According to this Google blogpost:
It’s best practice to place your app icons in mipmap- folders (not the drawable- folders) because they are used at resolutions
different from the device’s current density.
I still don't get the reason to this.
Why cant we just place the app icons in the res/drawable folders too?
Also, if only the app icon should be placed in the mipmap folders, how do I create other drawable assets and place them in the drawable folders with the Android Studio Image Asset wizard? (Accessed by right clicking in the project, selecting New > Image Asset)
Why cant we just place the app icons in the res/drawable folders too?
Oh, you can. Google doesn't recommend it, that's all.
Quoting myself from Version 6.5 of my book:
While
drawable resources might be removed when packaging an APK, such as for the
Gradle for Android split system for making density-specific editions of an app,
mipmap resources are left alone, apparently
This is because launcher icons may be pulled from a higher-density bucket than the regular device density that is used for all other drawables. Putting them in res/mipmap-*/ directories means that we won't inadvertently get rid of them as part of optimizing APK size.
(why they didn't handle this in a better way, I have no idea)
how do I create other drawable assets and place them in the drawable folders with the Android Studio Image Asset wizard? (Accessed by right clicking in the project, selecting New > Image Asset)
The Image Asset wizard only puts launcher icons in res/mipmap-*/ directories. If you choose the other icon types, they will go in res/drawable-*/. And, of course, the Image Asset wizard itself is optional.
I am using more than 400 images in my android application each of different sizes placed in
respective drawable folders(ldpi, mdpi, hdpi, xhdpi, xxhdpi).
This makes my app heavy.
Is there any way to use only one image size for all the android devices of different screen
densities?
I have used 9-patch images but it looks very blurred especiallyin ldpi devices.
I have tried to use SVG but getting error- java.lang.UnsupportedOperationException.
I dont know whether I am going wrong with adding SVG jar file in my android application.
Please provide me the steps for adding SVG jar file in my android application.
Please let me know if there is any solution other than 9-patch and SVG that I can use for
making android application.
You can make a single drawable folder and store all your images in the one folder.
res/drawable
store all your xxhdpi images in xxhdpi drawable and no need to store mdpi,ldpi,hdpi images in respective drawable folders.